Telling Movie Clips What to Do

I l @ ve RuBoard

Suppose that you have a movie that contains a simple animated movie clip. The main movie is simple: just one frame with a movie clip on it. The movie clip itself is a long animation of some sort , but it is all self-contained inside the movie clip. It contains no ActionScript code at all.

The first thing that you need to do to control a movie clip is to name it. Naming movie clips in Flash is confusing because all movie clips have two names: the name of the original movie clip in the Library, and the name of the movie clip instance in the work area. The reason for the two names is that you can have more than one instance of the same movie clip on the screen at the same time.

So, for instance, you could have a movie clip called "gear animation" in the Library, and a "gear1" movie clip instance on the screen. You could also have a "gear2" movie clip instance. They are both taken from the original "gear animation" movie clip in the Library.

Figure 6.1 shows the property panel when a movie clip is selected. To bring up the property panel, select the movie clip in the work area and choose Window, Properties.

Figure 6.1. The properties panel shows the name of the movie clip instance and allows you to change that name if you want.

graphics/06fig01.jpg

In Figure 6.1, you can see that I have named the movie clip instance "gears". It also shows the name of the original Library element as "gear animation".

The name of the movie clip instance on the screen is the critical one to an ActionScript programmer. This name is what you will need to refer to the movie clip in your programs.

For example, if you have a movie clip instance named "gears", you would refer to it with that name. Then, using dot syntax, you could give it a command, such as stop . Here is an example:

 gears.stop(); 

You can also send other commands to a movie clip. For instance, if you want to tell a movie clip to go to a certain frame, you can use gotoAndStop .

 gears.gotoAndStop(5); 

Note that this is how you send commands to a movie clip that is at the current level. If you want to place a command on a frame inside this movie clip, you shouldn't use the name of the clip, just gotoAndStop . If you were to use the name of the movie clip, Flash would look for a movie clip instance named "gears" inside the current movie clip instance "gears" inside the main timeline ”two levels down rather than one.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net