Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Data and Data Types > About data types > About determining data type | |||
While testing and debugging your programs, you might discover problems that seem to be related to the data types of different items. Or if you use variables that are not explicitly associated with a data type, you might find it useful to know the data type of a given variable. Using ActionScript, you can determine an item's data type. You can use the typeof operator to return information about data.
Use the typeof operator to get the data types, but remember that typeof does not return information about the class to which an instance belongs.
The following example shows how you can use the typeof operator to return the kind of object that you trace:
// Create a new instance of LoadVars class. var my_lv:LoadVars = new LoadVars(); /* typeof operator doesn't specify class, only specifies that my_lv is an object */ var typeResult:String = typeof(my_lv); trace(typeResult); // object
In this example, you create a new String variable named myName, and then convert it into a Number data type:
var myName:String = new String("17");
trace(myName instanceof String); // true
var myNumber:Number = new Number(myName);
trace(myNumber instanceof Number); // true
For more information about these operators, see typeof operator and instanceof operator in the ActionScript 2.0 Language Reference. For more information on testing and debugging, see Using Flash. For more information on inheritance and interfaces, see Inheritance. For more information on classes, see Classes.
Flash CS3