
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
176
|
Chapter 8: Loop Statements
Conceptually, the loop statement has the right approach—it repetitively updates the
position of
ball_mc by small amounts, which should give the illusion of movement.
However, in practice,
ball_mc doesn’t move each time its _x position is changed,
because the Stage isn’t updated between loop iterations. Instead, we’d see
ball_mc
suddenly jump 500 pixels to the right—10 pixels for each of the 50 loop iterations—
after the script completes.
To allow the Stage to update after each execution of the
ball_mc._x += 10; state-
ment, we can use a timeline loop like this:
// CODE ON FRAME 1
ball_mc._x += 10;
// CODE ON FRAME 2
this.gotoAndPlay(1);
Because Flash updates the Stage between any two frames, the ball will appear to ani-
mate. But the timeline loop completely monopolizes the timeline it’s on. While it’s
running, we can’t animate any other content on that timeline. A better approach is to
put our timeline loop into an empty, two-frame movie clip. We’ll get the benefit of a
Stage update between loop iterations without freezing a timeline we may need for
other animation.
Creating an Empty-Clip Timeline Loop
The following steps show how to create an empty-clip timeline loop:
1. Create a new Flash movie.
2. Create a movie clip symbol, named ball, that contains a circle ...