<< Chapter < Page Chapter >> Page >

Listing 10 signals the end of the class named CustomEffectInstance .

The Driver class for the program named CustomEffect02

The two classes discussed above constitute the whole of the custom effect. I will provide and explain two different driver classes that use the same customeffect but use it in different ways. The driver class for the program named CustomEffect02 begins in Listing 11. A complete listing of this class is provided in Listing 21 near the end of the lesson.

Two ways to play effects

You learned in the earlier lesson titled Events, Triggers, and Effects that there are at least two different ways to cause an effect to be played on a component in an ActionScript program. One wayis to call the setStyle method on the component and associate an effect trigger with an effect. With that approach, the effect will be playedeach time the effect trigger fires.

The second way

The second way to play an effect on a component is to target an Effect object to the component and then call the play method on the effect object. This approach doesn't make explicit use of the effect trigger.

I will illustrate the second approach in the program named CustomEffect02 , and will illustrate the first approach later in the program named CustomEffect03 .

Beginning of the Driver class for CustomEffect02

The Driver class begins in Listing 11.

Beginning of the driver class for customeffect02.

package CustomClasses{ import mx.containers.VBox;import mx.controls.Button; import mx.controls.Label;import mx.controls.Spacer; import flash.events.MouseEvent;public class Driver extends VBox{//Instantiate and save references to all of the // objects needed by the program.private var title:Label = new Label(); private var btnA:Button = new Button();private var btnB:Button = new Button(); private var spacer:Spacer = new Spacer();private var theEffect:CustomEffect = new CustomEffect();

The code in Listing 11 extends the VBox class and instantiates objects for all of the components that will be required to producethe GUI shown in Figure 1. In addition, Listing 11 instantiates an object of the new CustomEffect class.

No target is passed to the constructor

As you can see from Listing 11, a target component was not passed to the constructor for the CustomEffect class. Instead, an alternative approach that sets the targets property will be used.

Beginning of the constructor for the Driver class

The constructor for the Driver class begins in Listing 12.

Beginning of the constructor for the driver class.

public function Driver(){//constructor //Make some space at the top of the display.spacer.height = 40; addChild(spacer);//Set title properties and add to the VBox.title.setStyle("color","0xFFFF00"); title.setStyle("fontSize",14);title.text = "Demo custom effect"; addChild(title);//Instantiate two buttons and add them to the VBox. // Register the same event listener on both of// them. btnA.label = "Click me and watch the effect.";btnA.addEventListener(MouseEvent.CLICK,handler); addChild(btnA);btnB.label = "Or click me instead.";btnB.addEventListener(MouseEvent.CLICK,handler); addChild(btnB);

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask