Erm, that's it!...
5 Answers
flash.utils.getQualifiedClassName(...)
You can pass any ActionScript value to this function to get a String containing its fully qualified class name.

- 13,162
- 17
- 86
- 124

- 2,521
- 25
- 19
The function is called typeof(). http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#typeof

- 4,716
- 4
- 30
- 33
-
7Will give you back 'object' for all but 5 predfined types. – spender Aug 28 '09 at 03:35
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

- 334
- 2
- 14
If memory serves me right, a method flash.utils.describeType hands you an xml document with all reflected typeinfo of an object/type.

- 117,338
- 33
- 229
- 351
-
Whoah, that's actually way too much info about types. I was hoping it also included actual values of properties. Oh well, good to know about anyway. – Pat Jul 30 '15 at 15:06
The is
operator is the up to date solution:
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true

- 2,594
- 1
- 22
- 31
-
That doesn't answer the question though, the question is "given a variable, how do I find out its type", not "given a variable how do I tell if it is a given type". – Adam Parkin Jul 21 '14 at 20:32
-
If the user knows the possible types of var, or wants to find out if the var is or is not a particular type then this solution will work. Some of the other answers refer to deprecated functions (eg. typeof). – Ross Attrill Jul 22 '14 at 02:33