Erm, that's it!...
String data type Strings are immutable values, just as they are in the Java programming language. An operation on a String value returns a new instance of the string. The default value for a variable declared with the String data type is null . The value null is not the same as the empty string ( "" ).
To declare a new variable, we use the var statement. For example: var speed; var bookTitle; var x; The word var tells the interpreter that we're declaring a variable, and the text that follows, such as speed, bookTitle, or x, becomes our new variable's name.
flash.utils.getQualifiedClassName(...)
You can pass any ActionScript value to this function to get a String containing its fully qualified class name.
The function is called typeof(). http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#typeof
If you only need the most fundamental description of it's type, then you can use the typeof operator, like so:
var foo:String = "test";
trace( typeof foo );
// string
While this is convenient it has a drawback. That being it always gives the base type of the variable, for example:
var foo:Array = ["A","B","C","D"];
trace( typeof foo );
//object
var bar:int = 5;
trace( typeof bar );
//number
var hummer:Car = new Car();
trace( typeof hummer );
//Vehicle
Which are both technically right, but may not be what you're looking for.
If you want the more specific type (ie Array, String etc.) then you need to use the slightly more complicated getQualifiedClassName() function from the flash.utils package:
import flash.utils.getQualifiedClassName;
var foo:Array = ["A","B","C","D"];
trace( getQualifiedClassName( foo ) );
//Array
var bar:int = 5;
trace( getQualifiedClassName( bar ) );
//int
var hummer:Car = new Car();
trace( getQualifiedClassName( hummer ) );
//Car
typeof documentation
getQualifiedClassName() documentation
If memory serves me right, a method flash.utils.describeType hands you an xml document with all reflected typeinfo of an object/type.
Indeed: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType%28%29
The is operator is the up to date solution:
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true
See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6#is
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With