EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Calling Multiple Methods on a Single Movie Clip

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT
816 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
122 Chapter 7: Working with Movie Clips
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 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 allows you to specify the
target path to the instance that you want to control. For example, in the following script
startDrag() targets the customCursor instance and makes it draggable:
on(press){
startDrag("customCursor");
}
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 functions
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 Chapter 12, “ActionScript
Dictionary,” on page 205.
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 just movie clips.
The
with statement takes an object as a parameter. The object you specify is added to the end of
the current target path. All actions nested inside a with statement are carried out inside the new
target path, or scope. For example, in the following script, the
with statement is passed the object
donut.hole to change the properties of hole:
with (donut.hole){
_alpha = 20;
_xscale = 150;
_yscale = 150;
}
The script behaves as if the statements inside the with statement were called from the Timeline of
the hole instance. The above code is equivalent to the following:
donut.hole._alpha = 20;
donut.hole._xscale = 150;
donut.hole._yscale = 150;

Table of Contents

Related product manuals