![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
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 hitTest()
and swapDepths()
, don't have corresponding function names.
The following example illustrates the difference between using a method and using a function. Both statements duplicate the instance my_mc
, name the new clip newClip
, and place it at a depth of 5.
my_mc.duplicateMovieClip("newClip", 5); duplicateMovieClip("my_mc", "newClip", 5);
When a function and a method offer similar behaviors, you can choose to control movie clips by using either one. The choice depends on your preference and 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 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()
.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |