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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

5.
Select Frame 1 of the Timeline, and then type the following ActionScript in the
Actions panel:
var i:Number;
for (i = 0; i < 5; i++) {
this.attachMovie("libraryLinkageClassName", "clip" + i + "_mc", i,
{_x:(i * 100)});
}
6.
Select Control > Test Movie to test the code in Flash Player.
Notice how five movie clips duplicate across the top of the Stage. This ActionScript
duplicates the movie clip symbol in the library and repositions the clips on the Stage at x
coordinates of 0, 100, 200, 300 and 400 pixels. The loop executes five times, with the
variable
assigned a value of 0 through 4. On the last iteration of the loop, the value of
i
increments to 4 and the second expression (
loop to exit.
Remember to include a space following each expression in a
information, see the
for statement
Using for..in loops
Use the
statement to loop through (or iterate through) the children of a movie clip,
for..in
properties of an object, or elements of an array. Children, referenced previously, include other
movie clips, functions, objects, and variables. Common uses of the
looping over instances on a timeline or looping over the key/value pairs within an object.
Looping over objects can be an effective way to debug applications because it lets you see what
data returns from web services or external documents such as text or XML files.
For example, you can use a
(object properties are not kept in any particular order, so properties appear in an
unpredictable order):
var myObj:Object = {x:20, y:30};
for (var i:String in myObj) {
trace(i + ": " + myObj[i]);
}
This code outputs the following in the Output panel:
x: 20
y: 30
You can also iterate through the elements of an array:
var myArray:Array = ["one", "two", "three"];
for (var i:String in myArray) {
trace(myArray[i]);
}
158
Syntax and Language Fundamentals
i < 5
in the ActionScript 2.0 Language Reference.
loop to iterate through the properties of a generic object
for...in
) is no longer true, which causes the
statement. For more
for
for..in
i
loop include

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