
MovieClip.onKeyDown () Event Handler
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
680
|
ActionScript Language Reference
that clip is on stage, regardless of whether the clip is playing or stopped. If a clip’s play-
head is moved by a gotoAndStop() function call, the clip’s onEnterFrame() event handler is
still triggered with each passing frame. And if every playhead of an entire movie has been
halted with a stop() function, all onEnterFrame() event handlers on all clips will still
execute.
The onEnterFrame() event normally is used to update the state of a movie clip repeatedly
over time. But an onEnterFrame() event handler need not apply directly to the clip that
bears it—onEnterFrame() can be used on a movie’s main timeline or on a single-frame,
empty clip to execute code repeatedly. This technique, called a clip event loop (or, more
loosely, a process) is demonstrated in “Timeline and Clip Event Loops” in Chapter 8. The
setInterval() function is also a useful tool for repeatedly executing code.
To stop a callback from handling the onEnterFrame() event, use the delete operator to
remove the handler, as in:
// Make sure to omit the () operator after the function name!
delete theClip_mc.onEnterFrame;
Note that the code in an onEnterFrame() event handler is executed before any code that
appears on the timeline of the clip containing ...