MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 157

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

When you work with loops (and especially
that the loop can exit properly and does not end up in an infinite loop.
For more information on controlling loops, see
Using for loops
The
loop lets you iterate over a variable for a specific range of values. A
for
when you know exactly how many times you need to repeat a series of ActionScript
statements. This can be useful if you want to duplicate a movie clip on the Stage a certain
number of times or to loop over an array and perform a task on each item in that array. A
loop repeats an action using a built-in counter. In a
statement that increments the counter are all part of the
statement using the following basic format:
for (init; condition; update) {
// statements;
}
You must supply three expressions to a
a conditional statement that determines when the looping ends, and an expression that
changes the value of the variable with each loop. For example, the following code loops five
times. The value of the variable
through
, each on its own line.
4
var i:Number;
for (i = 0; i < 5; i++) {
trace(i);
}
In the next example, the first expression (
the first iteration. The second expression (
before the loop runs. The third expression (
each time after the loop runs.
To create a for loop:
1.
Select File > New and then select Flash Document.
2.
Create a movie clip on the Stage.
3.
Right-click the movie clip symbol in the Library panel and select Linkage from the
context menu.
4.
Select the Export for ActionScript check box, and type libraryLinkageClassName in the
Class text input field. Click OK.
and
while
"Using a switch statement" on page
for
statement: a variable that is set to an initial value,
for
starts at
and ends at
i
0
) is the initial expression that evaluates before
i = 0
) is the condition that you check each time
i < 5
) is called the post expression and is evaluated
i++
loops), always make sure
do..while
for
statement, the counter and the
statement. You write the
for
, and the output are the numbers
4
About statements
147.
loop is useful
for
for
0
157

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents