110
Data and Data Types
The following example presents another way to loop over objects. In this example, an object is
created and looped over using a
for..in
loop, and each property appears in the Output
panel:
var myObj:Object = {var1:"One", var2:"Two", var3:18, var4:1987};
var i:String;
for (i in myObj) {
trace(i + ": " + myObj[i]);
}
//outputs the following:
/*
var1: One
var2: Two
var3: 18
var4: 1987
*/
For information on creating for loops, see
Chapter 5, “Using for loops,” on page 157
. For
information on for..in loops, see
“Using for..in loops” on page 158
. For more information on
objects, see
Chapter 7, “Classes,” on page 225
.
About casting
ActionScript 2.0 lets you cast one data type to another. Casting an object to a different type
means you convert the value that the object or variable holds to a different type.
The results of a type cast vary depending on the data types involved. To cast an object to a
different type, you wrap the object name in parentheses (
()
) and precede it with the name of
the new type. For example, the following code takes a Boolean value and casts it to an integer.
var myBoolean:Boolean = true;
var myNumber:Number = Number(myBoolean);
For more information on casting, see the following topics:
■
“About casting objects” on page 111
Содержание 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...