Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Animation, Filters, and Drawings > Using filter effects > 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.
this.createEmptyMovieClip("my_mc", 10);
// draw square
with (my_mc) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(100, 0);
lineTo(100, 100);
lineTo(0, 100);
lineTo(0, 0);
endFill();
}
my_mc._x = 100;
my_mc._y = 100;
// use default DropShadowFilter values
my_mc.filters = [new flash.filters.DropShadowFilter()];
trace(my_mc.filters[0].distance); // 4
var filter_array:Array = my_mc.filters;
filter_array[0].distance = 10;
my_mc.filters = filter_array;
trace(my_mc.filters[0].distance); // 10
The first section of this code uses the Drawing API to create a red square, and positions the shape on the Stage. The second section of code applies a drop shadow filter to the square. Next, the code creates a temporary array to hold the current filters to apply to the red square on the Stage. The distance property of the first filter is set to 10 pixels, and the modified filter is reapplied to the my_mc movie clip instance.
|
NOTE |
|
Currently, no support is available for having any filters perform rotation based upon their parent's rotation or some sort of other rotation. The blur filter always blurs perfectly horizontally or vertically, independently of the rotation or skew of any item in the parent object tree. |
|
TIP |
|
Filtered content has the same restrictions on size as content with its |
For a source sample of using ActionScript to apply filters, Filters.fla, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ActionScript2.0/Filters folder to access this sample.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000971.html