CHAPTER 8
Working with Movie Clips
Movie clips are self-contained SWF files that run independently of each other and the Timeline
that contains them. For example, if the main Timeline has only one frame and a movie clip in
that frame has ten frames, each frame in the movie clip plays when you play the main SWF file. A
movie clip can, in turn, contain other movie clips, or nested clips. Movie clips nested in this way
have a hierarchical relationship, where the parent clip contains one or more child clips.
You can name movie clip instances to uniquely identify them as objects that can be controlled
with ActionScript. When you give a movie clip instance an instance name, the instance name
identifies it as an object of the MovieClip class type. You use the properties and methods of the
MovieClip class to control the appearance and behavior of movie clips at runtime.
You can think of movie clips as autonomous objects that can respond to events, send messages to
other movie clip objects, maintain their state, and manage their child clips. In this way, movie
clips provide the foundation of component-based architecture in Macromedia Flash MX 2004 and
Macromedia Flash MX Professional 2004. In fact, the components available in the Components
panel (Window > Development Panels > Components) are sophisticated movie clips that have
been designed and programmed to look and behave in certain ways. For information on creating
components, see "Creating Components" in Using Components.
About controlling movie clips with ActionScript
You can use global ActionScript functions or the methods of the MovieClip class to perform tasks
on movie clips. Some MovieClip methods perform the same tasks as functions of the same name;
other MovieClip methods, such as
and
, don't have corresponding
hitTest()
swapDepths()
function names.
The following example shows the difference between using a method and using a function. Each
statement duplicates the instance
, names the new clip
, and places it at a depth
my_mc
newClip
of 5.
my_mc.duplicateMovieClip("newClip", 5);
duplicateMovieClip("my_mc", "newClip", 5);
205
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers