Making Movie Clips Perform in Flash MX - Creating Movie Clips (Page 3 of 4 )
We usually treat movie clips just as we treat objects—we set their properties with the dot operator; we invoke their methods with the function-call operator (parentheses); and we store them in variables, array elements, and object properties. We do not, however, create movie clips in the same way we create objects. We cannot literally describe a movie clip in our code as we might describe an object with an object literal. And we cannot generate a movie clip with the new operator:
myClip = new MovieClip(); // Nice try buddy, but it won't work
Although Flash Player 6 supports the new MovieClip( ) command, that command establishes a MovieClip subclass; it cannot be used to create a new movie clip instance in a movie. Instead, we normally create movie clips directly in the authoring tool, by hand. Once a clip is created, we can use commands such as duplicateMovieClip() and attachMovie() to make new, independent duplicates of it. As of Flash Player 6, we can also create a completely new movie clip at runtime with the createEmptyMovieClip( ) method.
Movie Clip Symbols and Instances
Just as all object instances are based on a class, all movie clip instances are based on a template movie clip, called a symbol (sometimes called a definition). A movie clip’s symbol acts as a model for the clip’s content and structure. With the exception of clips created via createEmptyMovieClip(), we generate a specific clip instance from a movie clip symbol stored in the Library. Using a symbol, we can both manually and programmatically create clips to be rendered in a movie.
A specific copy of a movie clip symbol is called an instance. Instances are the individual clip objects that can be manipulated with ActionScript; a symbol is the mold from which instances of a specific movie clip are derived. Movie clip symbols are created in the Flash authoring tool. To make a new, blank symbol, we follow these steps:
Select Insert -> New Symbol. The Create New Symbol dialog box appears.
In the Name field, type an identifier for the symbol.
For Behavior, select the Movie Clip radio button.
Click OK.
Normally, the next step is to fill the symbol’s canvas and timeline with the content of our movie clip. Once a symbol has been created, it resides in the Library, waiting for us to use it to instantiate a movie clip instance. However, it is also possible to convert a group of shapes and objects that already exist on stage into a movie clip symbol. To do so, we follow these steps:
Select the desired shapes and objects.
Select Insert -> Convert to Symbol.
In the Name field, type an identifier for the symbol.
For Behavior, select the Movie Clip radio button.
Click OK.
The shapes and objects we select to create the new movie clip symbol are replaced by an unnamed instance of that new clip. The corresponding movie clip symbol appears in the Library, ready to be used to create further instances.