
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
220
Chapter 10
CHAPTER 10
Events and Event Handling
You’ve learned a lot about composing instructions for the ActionScript interpreter to
execute. By now you should be pretty comfortable telling the interpreter what you
want it to do, but how do you tell it when to perform those actions? ActionScript code
doesn’t just execute of its own accord—something always provokes its execution.
That “something” is either the synchronous playback of a movie or the occurrence of
a predefined asynchronous event.
Synchronous Code Execution
As a movie plays, the timeline’s playhead travels from frame to frame. Each time the
playhead enters a new frame, the interpreter executes any code attached to that
frame. After the code on a frame has been executed, the screen display is updated
and sounds are played. Then, the playhead proceeds to the next frame.
For example, when we place code directly on frame 1 of a movie, that code executes
before the content in frame 1 is displayed. If we place another block of code on a
keyframe at frame 5 of the same movie, frames 1 through 4 will be displayed, then
the code on frame 5 will be executed, then frame 5 will be displayed. The code exe-
cuted on frames 1 and 5 is said to be executed synchronously because it happens in a
linear, predictable fashion.
All code attached ...