- Telling Movie Clips What to Do
- Task: Animation Playback Controller
- Targeting Movie Clips
- Movie Clip Scripts
- Task: Backward Movie Clip
- Task: Clips Controlling Other Clips
- Summary
- Q&A
- Workshop
Task: Animation Playback Controller
Now let's put this knowledge to work. In the example movie 06animationplayback.fla there is a movie clip named "gears". Other elements on the main timeline are buttons that will control this movie clip.
The "gears" movie clip is nothing special. It contains 60 frames of animation. No scripts or markers are in it at all.
The goal here is to build a movie that controls the movie clip completely. It allows the user to click buttons to advance the movie clip frame-by-frame, play the movie clip at its normal rate, stop the movie clip, and send the movie clip back to the first frame.
Create a new Flash movie. Create movie clip animation in it, or simply steal the "gear animation" movie clip from the sample movie.
Drag the movie clip from the Library to the work area. Choose Windows, Properties so that you can change the name of the movie clip to "gears".
Place a script in the first and only frame of the main timeline. This script prevents the movie clip from animating when you first run the movie:
-
Create a set of buttons. You will need a button for the following actions: Advance, Previous, Play, Stop, and Rewind. Place them all in the work area under the movie clip. Figure 6.2 shows how this looks in the sample movie.
The Advance button uses the nextFrame command, addressed to the movie clip, to advance the clip one frame at a time.
The Previous button uses the prevFrame command, in the same manner, to move the movie clip back one frame.
The Play button uses the play command to let the movie clip advance and loop as it would normally.
Likewise, the Stop button issues a stop command to the movie clip.
The Rewind button does something a little different. It uses the gotoAndStop command to send the movie clip back to Frame 1 and have it wait there.
gears.stop();
Figure 6.2 The sample movie features a movie clip animation and five buttons.
on (release) { gears.nextFrame(); }
on (release) { gears.prevFrame(); }
on (release) { gears.play(); }
on (release) { gears.stop(); }
on (release) { gears.gotoAndStop (1); }
Test this movie. If none of the buttons seem to work, the most likely reason is that the movie clip is not named properly.
Imagine this same example movie, but with a cartoon or other animation instead of the simple one here. The Flash movie then acts like a viewer for the animation.