10.4. Event HandlersNot every event triggers the execution of code. Events regularly occur without affecting a movie. A user may, for example, generate dozens of events by clicking repeatedly on a button, but those clicks may be ignored. Why? Because, on their own, events can't cause code to execute -- we must write code to react to events explicitly. To instruct the interpreter to execute some code in response to an event, we add a so-called event handler that describes the action to take when the specified event occurs. Event handlers are so named because they catch, or handle, the events in a movie. An event handler is akin to a specially named function that is automatically invoked when a particular event occurs. Creating an event handler is, hence, very much like creating a function, with a few twists:
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|