<< Chapter < Page Chapter >> Page >

In addition, you can create your own effects.

One trigger, many effects

The same trigger can be used to trigger different types of effects. I suppose that in theory, you could create a different behavior for all possiblecombinations of the thirteen triggers and the sixteen different effects in the two lists provided above. In addition, you can program for multipleeffects to play in response to a single trigger.

To use an effect...

By default, Flex components do not play an effect when a trigger occurs. To configure a component to use an effect, you must associate an effect with atrigger.

Preview

Two ways to play effects

There are at least two different ways to cause an effect to be played on a component in an ActionScript program. One way is to call the setStyle method on the component and associate an effect trigger with an effect.With that approach, the effect will be played each time the effect trigger fires.

The second way

The second way 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.

Two different programs

I will present and explain two different programs in this lesson. The first program will illustrate the first approach described above. Thesecond program will illustrate and contrast the two approaches.

Discussion and sample code

A simple MXML file

Both programs that I will explain in this lesson are written almost entirely in ActionScript. There is just enough MXML code to make it possible to launch the programs from abrowser window.

The MXML file is shown in Listing 1 and also in Listing 16.

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>

As you can see, this MXML file simply instantiates an object of the class named Driver in the cc namespace. Beyond that, the entire behavior of the program is controlled by ActionScript code.

The program named Effects04

Will explain in fragments

I will break the code for these two programs down and explain the code in fragments. Complete listings for the Driver classes for the two programs are provided in Listing 17 and Listing 18 near the end of the lesson.

Program output at startup

You can run this program online to get a better feel for its behavior.Figure 1 shows the program output at startup.

Program output at startup for effects04.

Missing image
Program output at startup for Effects04.

As you can see, the Flash Player output consists of a label and a button with the text "Click me and watch me glow" .

Associate a trigger with an effect

This program associates a mouseUpEffect trigger with a Glow effect to cause the button to glow when the user releases the mouse button while the mouse pointer is over the button.

Program output after clicking the button

Figure 2 shows the program output shortly after clicking the button.

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