Using ActionScript 3.0 Components |
|
|
|
| Working with Components > Handling events > About event listeners | |||
The following key points apply to handling events for ActionScript 3.0 components:
addEventListener() method for the component instance. For example, the following line of code adds a listener for the MouseEvent.CLICK event to the Button instance aButton:
aButton.addEventListener(MouseEvent.CLICK, clickHandler);
The second parameter of the addEventListener() method registers the name of the function, clickHandler, to be called when the event occurs. This function is also referred to as a callback function.
aButton.addEventListener(MouseEvent.CLICK, clickHandler1); aButton.addEventListener(MouseEvent.CLICK, clickHandler2);
aButton.addEventListener(MouseEvent.CLICK, clickHandler1); bButton.addEventListener(MouseEvent.CLICK, clickHandler1);
removeEventListener() method. For example, the following line of code removes the listener for the MouseEvent.CLICK event on aButton:
aButton.removeEventListener(MouseEvent.CLICK, clickHandler);
|
|
|
|