MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual page 59

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

gotoAndPlay("startProgram");
}
If you want to check for one of several conditions, you can use the
multiple
else if
Repeating actions
ActionScript can repeat an action a specified number of times or while a specific condition exists.
Use the
,
while
do..while
To repeat an action while a condition exists:
Use the
while
A
loop evaluates an expression and executes the code in the body of the loop if the
while
expression is
true
In the following example, the loop executes four times:
i = 4;
while (i>0) {
my_mc.duplicateMovieClip("newMC"+i, i, {_x:i*20, _y:i*20});
i--;
}
You can use the
loop, the expression is evaluated at the bottom of the code block so the loop always
do..while
runs at least once.
This is shown in the following example:
i = 4;
do {
my_mc.duplicateMovieClip("newMC"+i, i, {_x:i*20, _y:i*20});
i--;
} while (i>0);
To repeat an action using a built-in counter:
Use the
statement.
for
Most loops use some kind of counter to control how many times the loop executes. Each
execution of a loop is called an iteration. You can declare a variable and write a statement that
increases or decreases the variable each time the loop executes. In the
the statement that increments the counter are part of the action. In the following example, the
first expression (
second expression (
third expression (
for (var i = 4; i > 0; i--){
my_mc.duplicateMovieClip("newMC"+ i, i, {_x:i*20, _y:i*20});
}
statements.
,
, and
for
for..in
statement.
. After each statement in the body is executed, the expression is evaluated again.
statement to create the same kind of loop as a
do..while
) is the initial expression that is evaluated before the first iteration. The
var i = 4
) is the condition that is checked each time before the loop runs. The
i > 0
) is called the post expression and is evaluated each time after the loop runs.
i--
switch
actions to create loops.
Using condition statements
statement rather than
loop. In a
while
action, the counter and
for
59

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents