
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Types of Events
|
221
a user action, such as clicking the mouse, resizing the movie, or pressing a key. Other
events happen without user intervention, such as a sound completing or an XML
document loading. Just as the playhead entering a new frame executes synchronous
code attached to the frame, events can cause event-based code to execute. Event-
based code (code that executes in response to an event) is said to be executed asyn-
chronously because the triggering of events can occur at arbitrary times.
Synchronous programming requires us to dictate, in advance, the timing of our
code’s execution. Asynchronous programming, on the other hand, gives us the abil-
ity to react dynamically to events as they occur. Asynchronous code execution is crit-
ical to ActionScript and interactivity.
This chapter explores asynchronous (event-based) programming in Flash.
Types of Events
Conceptually, events can be grouped into two categories:
user events
Actions taken by the user (e.g., a mouseclick or a keystroke)
system events
Things that happen as part of the internal playback of a movie (e.g., a movie clip
appearing on stage or variables loading from an external file)
ActionScript does not distinguish syntactically between user events and system
events. An event triggered internally by a movie is no