ActionScript 3.0 event handling model

ActionScript 3.0 introduces a single event handling model that replaces the different event handling mechanisms that existed in previous versions of ActionScript. The new event model is based on the Document Object Model (DOM) Level 3 Events Specification.

For developers with experience using the ActionScript 2.0 addListener() method, it may be helpful to point out the differences between the ActionScript 2.0 event listener model and the ActionScript 3.0 event model. The following list describes a few of the major differences between the two event models:

The following example, which listens for a MouseEvent.CLICK event on a Button component called aButton, illustrates the basic ActionScript 3.0 event handling model:

aButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
    trace("clickHandler detected an event of type: " + event.type); 
    trace("the event occurred on: " + event.target.name); 
}

For more information on ActionScript 3.0 event handling, see Programming ActionScript 3.0. For more information on ActionScript 3.0 event handling for components, see "Handling events" on page 894.


Flash CS3