User Guide
1178 ActionScript classes
Filters can be applied in the Flash authoring tool at design-time, or at runtime using
ActionScript code. To apply a filter using ActionScript, you must make a temporary copy of
the entire
TextField.filters array, modify the temporary array, and then assign the value
of the temporary array back to the
TextField.filters array. You cannot directly add a new
filter object to the
TextField.filters array. The following code has no effect on the target
text field, named
myTextField:
myTextField.filters[0].push(myDropShadow);
To add a filter using ActionScript, you must follow these steps (assume that the target movie
clip is named
myTextField):
■ Create a new filter object using the constructor function of your chosen filter class.
■ Assign the value of the myTextField.filters array to a temporary array, such as one
named
myFilters.
■ Add the new filter object to the temporary array, myFilters.
■ Assign the value of the temporary array to the myTextField.filters array.
If the
filters array is empty, you need not use a temporary array. Instead, you can directly
assign an array literal that contains one or more filter objects that you have created.
To modify an existing filter object, whether it was created at design-time or at runtime, you
must use the technique of modifying a copy of the
filters array, as follows:
■ Assign the value of the myTextField.filters array to a temporary array, such as one
named
myFilters.
■ Modify the property using the temporary array, myFilters. For example, if you want to
set the
quality property of the first filter in the array, you could use the following code:
myList[0].quality = 1;
■ Assign the value of the temporary array to the myTextField.filters array.
To clear the filters for a text field, set
filters to an empty array ([]).
If you are working with a
filters array that contains multiple filters and you need to track
the type of filter assigned to each array index, you can maintain your own
filters array and
use a separate data structure to track the type of filter associated with each array index. There
is no simple way to determine the type of filter associated with each
filters array index.
Availability: ActionScript 1.0; Flash Player 8
Example
The following example adds a drop shadow filter to a text field named
myTextField.
var myDropFilter = new flash.filters.DropShadowFilter();
var myFilters:Array = myTextField.filters;
myFilters.push(myDropFilter);