Home > Articles > Graphics & Web Design > Dreamweaver & Flash

  • Print
  • + Share This
This chapter is from the book

Lesson 22: Using Movie Clips to Change What Is on the Screen

Unfortunately, in Flash you can't swap one movie clip for another on the Stage. One way to make up for this is to remove one movie clip and create another in its place. But when you have a single movie clip that needs to change its image often, you need a quicker way to do it.

Another method is to create a movie clip that contains all the different states of that object. For instance, if the object is a spaceship, I might have frames in that movie that represent the spaceship without any engines on, the spaceship with the main engine on, the spaceship with the left engine on, the spaceship with the right engine on, and a series of frames that make up an animation of the spaceship exploding.

Example file: Changingimages.fla

In Changingimages.fla, there are buttons on the left that allow you to select which part of the "ship" movie clip will be shown. Figure 3.7 shows you what this movie looks like.

Figure 3.7Figure 3.7 Changingimages.fla lets you play with a single movie clip to have it show different views of the same object.

Each of the buttons in Changingimages.fla takes the movie clip to a different frame. For instance, this is the script on the up button:

on (press) {
  ship.gotoAndStop("up");
}

The code on the Explode button is different from all the rest because it uses gotoAndPlay so that the movie clip jumps to the "explode" frame and continues to animate.

on (press) {
  ship.gotoAndPlay("explode");
}

The movie clip contains an eight-frame sequence starting with "explode" that shows the explosion. The last frame of this sequence has a stop() command placed on it so that when the explosion is done, the movie clip waits on that last frame, which is blank, instead of looping back around to the first frame of the movie clip.

Check out Changingimages.fla from the CD and pay special attention to the timeline inside the "ship" movie clip. This is where the frames are labeled so that the code can use frame names rather than numbers.

  • + Share This
  • 🔖 Save To Your Account