Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Getting started with ActionScript > Working with objects > Events > Examining the event-handling process | |||
The following is a step-by-step description of the process that happens when you create an event listener. In this case, it's an example of creating a listener function that is called when an object named myButton is clicked.
The actual code written by the programmer is as follows:
function eventResponse(event:MouseEvent):void
{
// Actions performed in response to the event go here.
}
myButton.addEventListener(MouseEvent.CLICK, eventResponse);
Here is how this code would actually work when it's running in Flash Player:
eventResponse().
addEventListener() method on the event source object (named myButton) and passing the eventResponse function as a parameter.
myButton has a list of functions that are listening to each of its events, so when its addEventListener() method is called, myButton stores the eventResponse() function in its list of event listeners.
myButton object, triggering its click event (identified as MouseEvent.CLICK in the code).
At that point, the following occurs:
myButton. It goes through these functions one by one, calling each function and passing the event object to the function as a parameter. Since the eventResponse() function is one of myButton's listeners, as part of this process Flash Player calls the eventResponse() function.
eventResponse() function is called, the code in that function runs, so your specified actions are carried out.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000022.html