
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
234
|
Chapter 10: Events and Event Handling
clip._x += x;
clip._ y += y;
}
// CODE ON CLIP
// Call the main timeline function and tell it to move the
// current clip by passing a reference with the this keyword
onClipEvent (enterFrame) {
_root.move(this, 10, 15);
}
In Flash Player 5.0.30.0, a bug prevents gotoAndStop() and
gotoAndPlay() from working inside a clip handler when used with
string literal labels. Such commands are simply ignored. For example,
this does not work:
onClipEvent (load) {
gotoAndStop("intro"); // Won't work in Flash 5.0.30.0
}
To work around the bug, use a self-reflexive clip reference (i.e., this),
as in:
onClipEvent(load) {
this.gotoAndStop("intro");
}
Remember that statements in onClipEvent( ) handlers are scoped to
the clip’s timeline, not to the handler function’s local scope or the
clip’s parent timeline (the timeline upon which the clip resides).
For example, suppose we place our ball clip on the main timeline of a movie, and
the main timeline (not
ball’s timeline) has a moveBall( ) function defined on it. We
may absent-mindedly call moveBall( ) from an event handler on
ball, like this:
onClipEvent (enterFrame) {
moveBall( ); // Does nothing! There's no moveBall() function in ball.
// The moveBall() function is defined on _root.
}
We must refer to the moveBall( ) function ...