<< Chapter < Page | Chapter >> Page > |
Extends the class named EffectInstance
This class extends the class named EffectInstance . As before, the code in this class will override methods inherited from the EffectInstance class.
Instantiate and save references to standard effects
Listing 6 instantiates and saves references to the WipeRight , Rotate , and Glow effect classes. They will be combined to run concurrently later in the program.
Declare variables for storage of effect properties
Listing 7 declares a set of variables that will be used to store the properties for the three different effects that are combined to create acomposite effect.
//Variables for the storage of effect properties.
public var theDuration:Number;public var rotateAngleFrom:Number;
public var rotateAngleTo:Number;public var wipeShowTarget:Boolean;
public var glowColor:uint;public var glowInner:Boolean;
public var glowStrength:Number;
Property values are stored in these variables by the code in the initInstance method shown in Listing 4.
The constructor for the CustomEffectInstance class
The constructor for the class is shown in its entirety in Listing 8.
public function CustomEffectInstance(
theTarget:Object){super(theTarget);
//Set the target for all three individual effects.rotateEffect.target = theTarget;
wipeEffect.target = theTarget;glowEffect.target = theTarget;
} //end constructor
The target component
As was the case in Listing 3, this constructor receives a parameter of the generic type Object , which specifies the component on which the effect will be played.
A different EffectInstance object for each target component
If multiple target components are specified by setting the targets property of the CustomEffect class, different objects of the CustomEffectInstance class are instantiated and targeted to the different components in the list of targetcomponents.
Target the WipeRight, Rotate, and Glow effects to the target component
The code in the constructor sets the specified target to be the target for the three types of standard effects that will be played concurrently.
Override the inherited play method
You may have noticed that the code in the CustomEffect class didn't include any of the operational details regarding the nature of the custom effect. Those details are programmed into an overridden play method that begins in Listing 9.
override public function play():void{
super.play();//Note: The following values cannot be set in the// constructor because the variables aren't stable
// at that point in time.//Configure the rotate effectrotateEffect.angleFrom = rotateAngleFrom;
rotateEffect.angleTo = rotateAngleTo;rotateEffect.duration = theDuration;//Configure the wipe effect.
wipeEffect.showTarget = wipeShowTarget;wipeEffect.duration = theDuration;//Configure the glow effect.glowEffect.color = glowColor;
glowEffect.duration = theDuration;glowEffect.inner = glowInner;
glowEffect.strength = glowStrength;
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?