<< Chapter < Page Chapter >> Page >

This code instantiates an object of the Parallel class and adds the three effects as children of that object. Then the code calls the play method on the Parallel object. This causes all three effects to play simultaneously.

Reset the counter

Finally, Listing 15 resets the value of the effect counter back to 0 so that the sequence will begin anew the next time the event handler for the show event is executed.

Play the same effect on multiple targets simultaneously

You can play the same effect on multiple targets simultaneously by setting the targets property on the effect object instead of the target object. The targets property requires an array containing references to the target objects.

Three steps are required

The following steps are required to play an effect in the Flash Player using this approach.

  1. Instantiate and save a reference to an Effect object.
  2. Set properties on the effect object. Be sure to set the target property for a single target or the targets property for multiple targets.
  3. Call the play method on the effect object.

To play multiple effects in parallel or in sequence

  1. Instantiate and save references to two or more Effect objects.
  2. Set properties on the effect objects, being careful to set either the target property or the targets property.
  3. Instantiate a Parallel object or a Sequence object.
  4. Add the effect objects as children of the Parallel object or the Sequence object.
  5. Call the play method on the Parallel object or the Sequence object.

Note that you can also add Sequence objects to Parallel objects and vice versa. Just make certain that you don't try to play two instancesof the same effect on the same object at the same time.

The end of the program

Listing 15 also signals the end of the Driver class and the end of the program.

Run the programs

I encourage you to run these two programs from the web. Then copythe code from Listing 16 through Listing 18. Use that code to create Flex projects. Compile and run the projects.Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as theydo.

Resources

I will publish a list containing links to ActionScript resources as a separate document. Search for ActionScript Resources in the Connexions search box.

Complete program listings

Complete listings of the MXML and ActionScript files are provided in Listing 16 through Listing 18 below.

The mxml file used for both programs.

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>

The driver class for effects04.

/*Effects04 11/22/09 This program shows how to set the style on an object witha mouseUpEffect trigger and cause the object to glow. */package CustomClasses{ import mx.containers.VBox;import mx.controls.Button; import mx.controls.Label;import mx.effects.Glow; 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 button:Button = new Button();private var glowEffect:Glow = new Glow(); //--------------------------------------------------//public function Driver(){//constructor//Set title properties and add to the VBox. title.setStyle("color","0xFFFF00");title.setStyle("fontSize",14); title.text = "Demo mouseUpEffect trigger";addChild(title); button.label = "Click me and watch me glow.";addChild(button); glowEffect.color = 0xFF0000;glowEffect.strength = 255;glowEffect.duration = 10000; button.setStyle("mouseUpEffect",glowEffect);} //end constructor //--------------------------------------------------//} //end class } //end package

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