Manipulating filter effects with code 533
The preceding code is separated into three sections. The first section imports the required
classes and packages. The second section creates a nested movie clip that is used to load an
image and apply filters to the holder movie clip. The final section of code creates a new
MovieClipLoader instance and a listener for the movie clip loader. The listener object
defines a single event handler function,
onLoadInit, that is started once the image
successfully loads and is available on the Stage. First the image is repositioned to the center
of the Stage, then a new Tween object is created that animates the movie clip and applies a
blur filter of 0 and 10.
3. Select Control > Test Movie to test the Flash document.
Using the clone() method
The clone() method within each filter class returns a new filter instance with all of the same
properties as the original filter instance. When you work with filters, you might want to make
a copy of a filter, and to do so you need to duplicate the filter using the
clone() method. If
you do not use the clone method to duplicate a filter, Flash creates a reference to the original
filter only. If Flash creates a reference to the original filter, any change made to the duplicate
filter also modifies the original filter object.
The following procedure creates a new instance of a DropShadowFilter (
greenDropShadow),
calls the
clone() method to duplicate the green drop shadow filter, and saves a new filter
named
redDropShadow. The cloned filter sets a new drop shadow color, and both filters are
applied to a
flower_mc movie clip instance that’s on the Stage.
To use the clone method:
1. Create a new Flash document, and name it clone.fla.
2. Create a movie clip on the Stage.
3. Select the movie clip instance, and type flower_mc in the Instance Name text box in the
Property inspector.
4. Select Frame 1 of the Timeline, and add the following code in the Actions panel:
import flash.filters.DropShadowFilter;
var greenDropShadow:DropShadowFilter = new DropShadowFilter();
greenDropShadow.color = 0x00FF00; // green
var redDropShadow:DropShadowFilter = greenDropShadow.clone();
redDropShadow.color = 0xFF0000; // red
flower_mc.filters = [greenDropShadow, redDropShadow];