Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Animation, Filters, and Drawings > Manipulating filter effects with code > 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.
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];
The preceding code creates a new instance of the drop shadow filter and gives it the name greenDropShadow. The green drop shadow object is duplicated by using the DropShadowFilter.clone() method and creates a new filter object called redDropShadow. Both the green drop shadow and red drop shadow filters are applied to the flower_mc movie clip instance on the Stage. If you did not call the clone() method, both drop shadows would appear red. The reason for this appearance is that setting the redDropShadow.color property changes both the red drop shadow and green drop shadow objects because the red drop shadow contains a reference to the green drop shadow.
The filter is duplicated and cloned, and both filters are applied to the flower_mc instance.
For more information on the clone() method, see clone (DropShadowFilter.clone method) in the ActionScript 2.0 Language Reference. For related information, you can also see the clone() method of any filter class.
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/00000989.html