About statements
159
This code outputs the following in the Output panel:
three
two
one
For more information on objects and properties, see
“Object data type” on page 78
.
The following example uses
for..in
to iterate over the properties of an object:
To create a for loop:
1.
Select File > New and then select Flash Document.
2.
Select Frame 1 of the Timeline, and then type the following ActionScript in the
Actions panel:
var myObj:Object = {name:"Tara", age:27, city:"San Francisco"};
var i:String;
for (i in myObj) {
trace("myObj." + i + " = " + myObj[i]);
}
3.
Select Control > Test Movie to test the code in Flash Player.
When you test the SWF file, you should see the following text in the Output panel:
myObj.name = Tara
myObj.age = 27
myObj.city = San Francisco
If you write a
for..in
loop in a class file (an external ActionScript file), instance members are
not available within the loop, but static members are. However, if you write a
for..in
loop in
a FLA file for an instance of the class, instance members are available but static members are
not. For more information on writing class files, see
Chapter 7, “Classes,” on page 225
. For
more information, see the
for..in statement
in the
ActionScript 2.0 Language
Reference.
NO
TE
You cannot iterate through the properties of an object if it is an instance of a custom
class, unless the class is a dynamic class. Even with instances of dynamic classes, you
are able to iterate only through properties that are added dynamically.
NO
TE
The curly braces (
{}
) used to enclose the block of statements to be executed by the
for..in
statement are not necessary if only one statement executes.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...