Creating Movie Clips
We covered how to create a movie clip manually back in Chapter 5, "Symbols and the Library," but we will review it quickly here.
Creating Movie Clips Manually
To create a Movie Clip symbol manually, follow these steps:
That was pretty simple; you just created a movie clip manually. Now if you want to use it, drag an instance of it from the library onto the stage and give it an instance name.NOTEAlthough technically you do not need to give every instance of a movie clip object an instance name unless you plan to refer to it with ActionScript, it is good practice to do so. Also remember that you cannot duplicate instance names in the same timeline or errors will occur.Creating movie clips manually is not the only way to create them. You can also create them on-the-fly with ActionScript.
Creating Movie Clips with ActionScript
Since the MX version of Flash, users have been able to create movie clips with ActionScript. Before then, when you wanted an empty movie clip on the stage, you would have to create one manually, drag it onto the stage, and then give it an instance name.To create empty movie clips in ActionScript, use the createEmptyMovieClip() method, which looks like this:
The parameters of this method are as follows:
movieClip.createEmptyMovieClip(instanceName, depth);
- movieClip
The instance name of the movie clip where the empty clip will be created. - instanceName
This is a string literal that represents the instance name of the movie clip being created. - depth
This is a numerical value that represents the stacking order of the movie clip being created (more on depth later in this chapter).
That is the basic layout of the createEmptyMovieClip() method. The next example shows how to implement it.
1. | Create a new Flash document. |
2. | In the first frame of the main timeline, place these actions:
|
3. | Now test the movie by choosing Control, Test Movie. |
4. | Notice that when the movie runs, there isn't anything on the stage. This is because we created an empty movie clip; there is nothing inside it, but you can tell it's there. |
When you're in the test movie screen, choose Debug, List Objects, and you should see in the Output panel something similar to Figure 13.1.