home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeActionScript: The Definitive GuideSearch this book

10.4. Event Handlers

Not 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:


Most events were first introduced in Flash 5. If exporting to Flash 4 format, use only the button event handlers (only button events were supported in Flash 4), and test your work carefully in the Flash 4 Player.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.