User Guide
206 Chapter 8: Working with Movie Clips
When a function and a method offer similar behaviors, you can select to control movie clips by
using either one. The choice depends on your preference and your familiarity with writing scripts
in ActionScript. Whether you use a function or a method, the target Timeline must be loaded in
Flash Player when the function or method is called.
To use a method, invoke it by using the target path of the instance name, a dot (.), and then the
method name and parameters, as shown in the following statements:
myMovieClip.play();
parentClip.childClip.gotoAndPlay(3);
In the first statement, play() moves the playhead in the myMovieClip instance. In the second
statement,
gotoAndPlay() sends the playhead in childClip (which is a child of the instance
parentClip) to Frame 3 and continues to move the playhead.
Global functions that control a Timeline have a
target parameter that let you specify the target
path to the instance that you want to control. For example, in the following script
startDrag()
targets the instance the code is placed on and makes it draggable:
my_mc.onPress = function() {
startDrag(this);
};
my_mc.onRelease = function() {
stopDrag();
};
The following functions target movie clips: loadMovie(), unloadMovie(), loadVariables(),
setProperty(), startDrag(), duplicateMovieClip(), and removeMovieClip(). To use
these functions, you must enter a target path for the function’s
target parameter to indicate the
target of the function.
The following MovieClip methods can control movie clips or loaded levels and do not have
equivalent functions:
MovieClip.attachMovie(), MovieClip.createEmptyMovieClip(),
MovieClip.createTextField(), MovieClip.getBounds(), MovieClip.getBytesLoaded(),
MovieClip.getBytesTotal(), MovieClip.getDepth(), MovieClip.getInstanceAtDepth(),
MovieClip.getNextHighestDepth(), MovieClip.globalToLocal(),
MovieClip.localToGlobal(), MovieClip.hitTest(), MovieClip.setMask(),
MovieClip.swapDepths().
For more information about these functions and methods, see their entries in Flash ActionScript
Language Reference.
Calling multiple methods on a single movie clip
You can use the with statement to address a movie clip once and then execute a series of methods
on that clip. The
with statement works on all ActionScript objects (for example, Array, Color,
and Sound)—not only movie clips.