Writing Scripts with ActionScript > Using actions

Using actions

Actions are ActionScript's statements, or commands. Multiple actions assigned to the same frame or object create a script. Actions can act independently of each other, as in the following statements:

swapDepths("mc1", "mc2");
gotoAndPlay(15);

You can also nest actions by using one action inside another; this allows actions to affect each other. In the following example, the if action tells the gotoAndPlay action when to execute:

if (i >= 25) {
	gotoAndPlay(10);
}

Actions can move the playhead in the Timeline (gotoAndPlay), control the flow of a script by creating loops (do while) or conditional logic (if), or create new functions and variables (function, setVariable). The following table lists all ActionScript actions:
Actions

break

evaluate

include

print

stopDrag

call

for

loadMovie

printAsBitmap

swapDepths

comment

for...in

loadVariables

removeMovieClip

tellTarget

continue

fsCommand

nextFrame

nextScene

return

toggleHighQuality

delete

function

on

setVariable

stopDrag

do...while

getURL

onClipEvent

setProperty

trace

duplicateMovieClip

gotoAndPlay

gotoAndStop

play

startDrag

unloadMovie

else

if

prevFrame

stop

var

else if

ifFrameLoaded

prevScene

stopAllSounds

while


For syntax and usage examples of each action, see individual entries in ActionScript dictionary: Overview.

Note: In this help system, the ActionScript term action is synonymous with the JavaScript term statement.


 
Writing a target path

To use an action to control a movie clip or loaded movie, you must specify its name and its address, called a target path. The following actions take one or more target paths as arguments:

loadMovie
loadVariables
unloadMovie
setProperty
startDrag
duplicateMovieClip
removeMovieClip
print
printAsBitmap
tellTarget

For example, the loadMovie action takes the arguments URL, Location, and Variables. The URL is the location on the Web of the movie you want to load. The Location is the target path into which the movie will be loaded.

loadMovie(URL, Location, Variables);

Note: The Variables argument is not required for this example.

The following statement loads the URL http://www.mySite.com/myMovie.swf into the instance bar on the main Timeline, _root; _root.bar is the target path;

loadMovie("http://www.mySite.com/myMovie.swf", _root.bar);

In ActionScript you identify a movie clip by its instance name. For example, in the following statement, the _alpha property of the movie clip named star is set to 50% visibility:

star._alpha = 50;

To give a movie clip an instance name:

1 Select the movie clip on the Stage.
2 Choose Window > Panels > Instance.
3 Enter an instance name in the Name field.

To identify a loaded movie:

Use _levelX where X is the level number specified in the loadMovie action that loaded the movie.

For example, a movie loaded into level 5 has the instance name _level5. In the following example, a movie is loaded into level 5 and its visibility is set to false:

onClipEvent(load) {
    loadMovie("myMovie.swf", 5);
}
onClipEvent(enterFrame) {
	_level5._visible = false;
}

To enter a movie's target path:

Click the Insert Target Path button in the Actions panel, and select a movie clip from the list that appears.

For more information about writing target paths, see Working with movie clips: Overview.