<< Chapter < Page Chapter >> Page >
Listing

The driver class for effects05.

/*Effects05 11/22/09 This program demonstrates two ways to play effects:1. Call the play method on the effect. 2. Set the style on an object with a hideEffect trigger.*********************************************************/ package CustomClasses{import flash.events.MouseEvent;import mx.containers.VBox; import mx.controls.Button;import mx.controls.Label; import mx.effects.Glow;import mx.effects.Iris; import mx.effects.Parallel;import mx.effects.Rotate; import mx.effects.WipeRight;import mx.events.EffectEvent; import mx.events.FlexEvent;public class Driver extends VBox{ //Instantiate and save references to most 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 irisEffect:Iris = new Iris(); private var wipeEffect:WipeRight = new WipeRight();private var rotateEffect:Rotate = new Rotate(); private var glowEffect:Glow = new Glow();private var effectCounter:uint = 0; //--------------------------------------------------//public function Driver(){//constructor//Set title properties and add to the VBox. title.setStyle("color","0xFFFF00");title.setStyle("fontSize",14); title.text = "Demo two ways to play effects";addChild(title);//Put labels on the two buttons and disable one // of them.btnA.label = "Click me to show the other button."; btnB.label = "Click me to hide me.";btnA.enabled = false;//disable btnA at startup//Register click listeners on both buttons, // register a show listener on btnB, and add// them to the VBox. btnA.addEventListener(MouseEvent.CLICK,btnAhandler);btnB.addEventListener(MouseEvent.CLICK,btnBhandler); btnB.addEventListener(FlexEvent.SHOW,showHandler);addChild(btnA); addChild(btnB);//Configure an iris effect that will be played when// btnB is hidden. irisEffect.duration = 2000;irisEffect.addEventListener( EffectEvent.EFFECT_END,endEffectHandler);btnB.setStyle("hideEffect",irisEffect);//Configure a wipe effect that may be played // when btnB is shown.wipeEffect.target = btnB; wipeEffect.showTarget = true;wipeEffect.duration = 2000; //Configure a rotate effect that may be played// when btnB is shown. rotateEffect.target = btnB;rotateEffect.angleFrom = 0; rotateEffect.angleTo = 360;rotateEffect.duration = 2000;//Configure a glow effect that may be played // when btnB is shown.glowEffect.target = btnB; glowEffect.color = 0xFFFF00;glowEffect.duration = 4000; glowEffect.inner = true;glowEffect.strength = 255; } //end constructor//--------------------------------------------------// //This method is executed when btnB is clicked. It// hides itself, which in turn causes the Iris // hideEffect to be played on itself.private function btnBhandler(event:MouseEvent):void{ btnB.visible = false;} //end btnBhandler //--------------------------------------------------////This method is executed when btnA is clicked. It // disables itself and causes btnB to become visible.// This in turn causes btnB to dispatch a show event // which is handled by a different event handler.private function btnAhandler(event:MouseEvent):void{ btnA.enabled = false;btnB.visible = true; } //end btnAhandler//--------------------------------------------------// //This method is executed when btnB is hidden and the// iris effect ends. It enables btnA so that the user // can click btnA to show btnB again.private function endEffectHandler( event:EffectEvent):void{btnA.enabled = true; } //end event handler//--------------------------------------------------// //This method is executed when btnB becomes visible// and dispatches a show event. It causes any effects // that may be playing to end. Then it one of three// effects or all three in parallel depending on the // value of an effect counter.private function showHandler(event:FlexEvent):void{ //Make certain that none of the effects are playing.wipeEffect.end(); rotateEffect.end();glowEffect.end();//Select the effect or effects that will be // played.if(effectCounter == 0){ wipeEffect.play();effectCounter++;//increment the effect counter. }else if(effectCounter == 1){//Set the rotate origin to the center of the // button. This couldn't be done when the rotate// effect was configured because the true width // and height of the button weren't available at// that time. Another approach would be to use // a creationComplete event handler to set these// values. rotateEffect.originX = btnB.width/2;rotateEffect.originY = btnB.height/2; rotateEffect.play();effectCounter++; }else if(effectCounter == 2){glowEffect.play(); effectCounter++;}else{ //Play all three effects in parallel.var parallel:Parallel = new Parallel(); parallel.addChild(rotateEffect);parallel.addChild(glowEffect); parallel.addChild(wipeEffect);parallel.play(); effectCounter = 0;//reset the effect counter} //end else } //end showHandler//--------------------------------------------------// } //end class} //end package

Miscellaneous

This section contains a variety of miscellaneous materials.

Housekeeping material
  • Module name: Events, Triggers, and Effects
  • Files:
    • ActionScript0116\ActionScript0116.htm
    • ActionScript0116\Connexions\ActionScriptXhtml0116.htm
PDF disclaimer: Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

-end-

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