Types of Movie Clips
Not all movie clips are created equal. In fact, there are three distinct types of clips available in Flash:
- Main movies
- Regular movie clips
- Smart Clips
In addition to these three official varieties, we may define four further subcategories, based on our use of regular movie clips:
- Process clips
- Script clips
- Linked clips
- Seed clips
While these latter unofficial categories are not formal terms used in ActionScript, they provide a useful way to think about developing with movie clips. Let's take a closer look at each movie clip type.
Main Movies
The main movie of a Flash document contains the basic timeline and Stage present in every document. The main movie is the foundation for all the content in the document, including all other movie clips. We sometimes call the main movie the main timeline, the main movie timeline, the main Stage, or simply the root.
Main movies may be manipulated in much the same way as regular movie clips, however:
- A main movie cannot be removed from a swf file (although a swf file, itself, may be removed from the Flash Player).
- The following movie clip methods do not work when invoked on a main movie: duplicateMovieClip( ), removeMovieClip( ), swapDepths( ).
- Event handlers cannot be attached to a main movie.
- Main movies can be referenced through the built-in, global
_rootand_leveln properties.
Note that while each swf file contains only one main movie, more than one swf may reside in the Flash Player at once -- we may load multiple swf documents (and therefore multiple main movies) onto a stack of levels via the loadMovie( ) and unloadMovie( ) functions, which we'll study later.
Regular Movie Clips
Regular movie clips are the most common and fundamental content containers; they hold visual elements and sounds and can even react to user input and movie playback through event handlers. For JavaScript developers who are used to working with DHTML, it may be helpful to think of the main movie as being analogous to an HTML document object and regular movie clips as being analogous to that document's layer objects.
Smart Clips
Introduced in Flash 5, a Smart Clip is a regular movie clip that includes a graphical user interface used to customize the clip's properties in the authoring tool. Smart Clips are typically developed by advanced developers to provide an easy way for less-experienced Flash authors to customize a movie clip's behavior without knowing how the code of the clip works. We'll cover Smart Clips in detail in "ActionScript Authoring Environment".
Process Clips
A process clip is a movie clip used not for content but simply to repeatedly execute a block of code. Process clips may be built with an enterFrame event handler or with a timeline loop as we saw under "Timeline and Clip Event Loops" in "Loop Statements".
Process clips are ActionScript's unofficial alternative to the setTimeout( ) and setInterval( ) methods of the JavaScript window object.
Script Clips
Like a process clip, a script clip is an empty movie clip used not for content but for tracking some variable or executing some script. For example, we may use a script clip to hold event handlers that detect keypresses or mouse events.
Linked Clips
A linked clip is a movie clip that either exports from or imports into the Library of a movie. Export and import settings are available through every movie clip's Linkage option, found in the Library. We most often use linked clips when dynamically generating an instance of a clip directly from a Library symbol using the attachMovie( ) clip method, as we'll see later.
Seed Clips
Before the attachMovie( ) method was introduced in Flash 5, we used the duplicateMovieClip( ) function to create new movie clips based on some existing clip, called a seed clip. A seed clip is a movie clip that resides on stage solely for the purpose of being copied via duplicateMovieClip( ). With the introduction of attachMovie( ), the need for seed clips has diminished. However, we still use seed clips and duplicateMovieClip( ) when we wish to retain a clip's event handlers and transformations in the process of copying it.
In a movie that makes heavy use of duplicateMovieClip( ) to dynamically generate content, it's common to see a row of seed clips on the outskirts of the movie canvas. The seed clips are used only to derive duplicate clips and are, therefore, kept off stage.