
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
178
|
Chapter 8: Loop Statements
The onEnterFrame( ) loop frees us from nesting our code inside a movie clip and
doesn’t require a two-frame loop, as timeline loops do. All the action of a clip event
loop happens in a single event handler. To stop an onEnterFrame( ) loop, simply
remove the movie clip that bears it. For example:
processMoveBall_mc.removeMovieClip( );
Or, delete the onEnterFrame( ) handler:
delete processMoveBall_mc.onEnterFrame;
If our application is simple, we may wish to forego our empty clip onEnterFrame( )
loop altogether. In some cases, we can, quite legitimately, attach an event loop
directly to the clip being manipulated. In our
ball_mc example, we can avoid the
need for a separate empty clip by defining our onEnterFrame( ) handler directly on
the
ball_mc instance:
ball_mc.onEnterFrame = function ( ) {
this._x += 10;
}
We can even define the onEnterFrame( ) event loop on the main timeline by placing
this code on one of its frames:
this.onEnterFrame = function ( ) {
this.ball_mc._x += 10;
}
Notice that we intentionally avoid referring to the main timeline as _root, which may
change meaning if the entire movie is loaded into a movie clip.
In Flash Player 6, each movie clip (including the main timeline) can take only one
onEnterFrame( ) event handler. In most applications, ...