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 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
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;
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...