Types of Events in Flash


In a Flash environment there are three ways to work with events: using clip events, event handlers, and listeners. The first type of event, the clip event, is a way of placing code directly on a movie clip or button and having that code respond to an event. The following is an example:

    on(press) {       // do something     }


We will not be covering clip events in this lesson because they involve placing code directly on an object. This is considered bad practice and therefore clip events should be avoided. It's considered bad practice because your code is all over the place. Best practice is to place your code in external class files or designate a layer called Actions. In our examples, we will use an Actions layer, and all our code will be placed on frames in that layer. Because there are many different ways to handle events in Flash, you will always have a better option than using a clip event.

The second way to work with events in Flash is by using an event handler. The responses that come from pushing, holding, moving, entering, and leaving a movie clip are triggered by event handlers. Event handlers represent the first step in getting your movie to do anything interactivewhich is why a thorough understanding of them is vital. Handlers, sometimes referred to as callbacks, are also used in other classes besides the MovieClip. The LoadVars and XML classes use event handlers to trigger the onLoad events that occur when data has finished loading.

The third way to work with events is through listeners. The Key and Mouse classes use the listener model to handle events. Listeners have some distinct advantages over callbacks. We will cover those later in the lesson.




Macromedia Flash 8 ActionScript Training from the Source
Macromedia Flash 8 ActionScript: Training from the Source
ISBN: 0321336194
EAN: 2147483647
Year: 2007
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net