Handling Events

Events are actions that occur while a SWF file is playing. An event such as a mouse click or a keypress is called a user event because it occurs as a result of direct user interaction. An event that Flash Player generates automatically, such as the initial appearance of a movie clip on the Stage, is called a system event because it isn't generated directly by the user.

In order for your application to react to events, you must use event handlers--ActionScript code associated with a particular object and event. For example, when a user clicks a button on the Stage, you might advance the playhead to the next frame. Or when an XML file finishes loading over the network, the contents of that file might appear in a text field.

You can handle events in ActionScript in several ways:

Using event handlers with loadMovie (MovieClip.loadMovie method) can be unpredictable. If you attach an event handler to a button using on(), or if you create a dynamic handler using an event handler method such as onPress (MovieClip.onPress handler), and then you call loadMovie(), the event handler is not available after the new content is loaded. However, if you use onClipEvent handler or on handler to attach an event handler to a movie clip, and then call loadMovie() on that movie clip, the event handler is still available after the new content is loaded.

For more information on handling events, see the following sections:

About ActionScript and events
Using event listeners
Using event listeners with components
Using button and movie clip event handlers
Broadcasting events from component instances
Creating movie clips with button states
Event handler scope
Scope of the this keyword
Using the Delegate class

Flash CS3