EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - About Casting

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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 objectson page 111

Table of Contents

Related product manuals