<< Chapter < Page Chapter >> Page >

Very similar to the previous code

The code in Listing 15 matches the code in Listing 11 and Listing 12 with a few exceptions:

  • There is no import directive for the MouseEvent class.
  • There are no click event handlers registered on the buttons.

Set properties on the custom effect

Listing 16 sets the properties on the custom effect.

Set properties on the custom effect.

//Set various properties needed by the effect. theEffect.theDuration = 4000;theEffect.rotateAngleFrom = 0; theEffect.rotateAngleTo = 720;theEffect.wipeShowTarget = true; theEffect.glowColor = 0xFF0000;theEffect.glowInner = true; theEffect.glowStrength = 255;

Once again, this code is very similar to the code in Listing 13. There is one major difference, however. The targets property for the effect is not explicitly set to the buttons as is the case in Listing 13.

Apply the effect to the two buttons individually

Listing 17 shows the major difference between the two programs.

Apply the effect to the two buttons individually.

btnA.setStyle("mouseUpEffect",theEffect); btnB.setStyle("mouseUpEffect",theEffect);} //end constructor //--------------------------------------------------//} //end class } //end package

Use the setStyle method and the effect trigger

Whereas the previous program explicitly sets the buttons as targets of the effect and calls the play method on the effect, this program uses the setStyle approach and associates the custom effect with a mouseUpEffect trigger on each button individually. As a result, when the mouse button is released while the mouse pointer is over one ofthe buttons, the effect is played on that button alone.

May not be possible to specify multiple targets

I don't know of any easy way to use this approach to cause the effect to be played on two or more components at the same time. The documentation hints thatthis may not be possible.

The end of the program

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

Run the program

I encourage you to run this program from the web. Then copy the code from Listing 18 through Listing 22. 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 canexplain why your changes behave as they do.

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 Flex applications discussed in this lesson are provided below.

Common mxml code used for both programs.

<?xml version="1.0" encoding="utf-8"?><!--CustomEffect02 11/26/09 Illustrates a custom effect, which is the parallelplaying of three standard effects: WipeRightRotate GlowThe effect is applied to two buttons each time either button is clicked.This version sets the targets on the effect and calls the play method on the effect.See the Flex 3 Cookbook, page 363 Also see http://livedocs.adobe.com/flex/3/html/help.html?content=createeffects_2.html#178126 Also see http://livedocs.adobe.com/flex/3/html/help.html?content=behaviors_04.html#275399 --><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>

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