Using filter effects 501
When you use import statements, remember that classes are only imported for the level that
you specify. For example, if you import all classes in the
mx.transitions package, only the
classes within the /transitions/ directory are imported, not all classes within subdirectories
(such as the classes in the
mx.transitions.easing package).
For an example of using ActionScript to apply filters, you can find a sample source file,
Filters.fla, in the Samples folder on your hard disk.
■ In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Filters.
■ On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Filters.
Working with filters, caching, and the MovieClip class
If a movie clip has an associated filter, it’s marked to cache itself as a transparent bitmap when
the SWF file loads. As long as the movie clip has at least one filter applied to it, Flash Player
caches the movie clip as a bitmap at runtime by forcing the
cacheAsBitmap property to be
true. The cached bitmap is used as a source image for the filter effects. Each movie clip
usually has two bitmaps: one bitmap is the original unfiltered source movie clip, the second
bitmap is the final image after filtering. If you do not change the appearance of the movie clip
at runtime, the final image does not need to update, which helps improve performance.
You can access filters applied to an instance by calling the
MovieClip.filters property.
Calling this property returns an array that contains each filter object currently associated with
the movie clip instance. A filter itself has a set of properties unique to that filter, such as
the following:
trace(my_mc.filters[0].angle); // 45.0
trace(my_mc.filters[0].distance); // 4
You can access and modify filters as you would a regular array object. Setting and getting the
filters by using the property returns a duplicate of the filters object, not a reference.
To modify an existing filter, you can use code similar to the code in the following procedure.
TIP
If you import a class but don't use it in your script, the class isn't exported as part of the
SWF file. This means that you can import large packages without being concerned
about the size of the SWF file; the bytecode associated with a class is included in a SWF
file only if that class is actually used.