
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Event Handler Scope
|
231
onClipEvent (keyDown) {
this._visible = false;
}
onClipEvent (keyUp) {
this._visible = true;
}
7. Select Control ➝ Test Movie.
8. Click the movie to make sure it has keyboard focus, then press and hold any key.
Each time you depress a key, the
rectangle movie clip disappears. Each time you
release the depressed key,
rectangle reappears.
Unlike Flash 6’s event handler properties and event listeners, Flash 5’s on( ) and
onClipEvent( ) handlers cannot be attached and removed via ActionScript while the
movie is playing. Therefore, in Flash 5 the following event handler property assign-
ment is illegal:
theClip.onKeyDown = function ( ) {
_visible = 0;
};
We’ll see how to work around this shortcoming later in this chapter under “Dynamic
Movie Clip Event Handlers.”
Event Handler Lifespan
The lifespan of event handlers is tied to the life of the objects with which they are
associated. When a clip or button is removed from the Stage, or when an XML or
TextField object is deleted, any event handlers associated with those objects die with
them. An object must be present on stage or in code for its handlers to remain active.
Event Handler Scope
As with any function, the statements in an event handler or listener execute within a
predefined scope. Scope dictates where the interpreter ...