Controlling the Flow of the Movie in Flash MX
Sams Teach Yourself Flash MX ActionScript is designed for someone who wants to go beyond using Flash just for animation. It was written with the non-programmer in mind, but can be used by an experienced programmer to quickly translate what they know into ActionScript.
The book begins by explaining the basics of programming and how ActionScript can be used to control Flash movies. Each chapter builds upon the last with explanations, examples sample projects. Later chapters deal with more advanced programming topics like data structures, building interface elements and server communication.
The simplest, but in some ways the most powerful, thing that ActionScript can do is control the flow of the Flash movie. You can stop a movie on a certain frame, or jump around from frame to frame. This frees the Flash movie from its even-paced linear movement that it has by default.
In this hour, you will:
Learn how to stop the movie on a frame
Find out how to jump from one frame to another
Create buttons to allow the user to control the Flash movie
Make a simple slideshow
Create a full presentation with Flash
Stopping the Movie
Perhaps the simplest command in ActionScript is the stop command. When issued, it simply stops the movie in its tracks on the current frame.
Most of the time, you will want to place the stop command in a frame on the timeline. Although only stop is necessary, the Flash reference material shows the command with the optional parentheses, so we will use them here as well:
When you use the stop command, the movie is really just paused on the current frame. Any animation inside movie clips or graphic symbols on the frame continues to animate. However, animation on the main timeline stops.
For the movie to continue, you need to issue another ActionScript command. The simplest one is the play command. This pushes the movie forward to the next frame, and it continues playing.
We'll look at the play command in the section, "Creating Buttons," later in this hour. For now, let's just look at an example of the stop command.
The movie stop.fla on the CD-ROM is a simple example. The first frame contains a large graphic of the letter "A" on it. The second and third frames contain the letters "B" and "C," respectively.
The second frame of the movie also contains a script. It is a simple script with just the stop command. Figure 5.1 shows the work area and timeline for this movie. Notice that there is an "a" in the second frame, signifying a script there. The Actions panel is also shown in Figure 5.1. In it, you can see the script.
Figure 5.1 The "a" indicates a script in frame 2 of the timeline.
When you test the movie, the first frame with the "A" quickly appears. Then the movie moves on to the second frame with the "B." At this point, the stop command executes, and the movie stops on frame 2. Frame 3, with the "C" on it, never appears.