13

Erm, that's it!...

user84643
  • 379
  • 2
  • 5
  • 15

5 Answers5

25
flash.utils.getQualifiedClassName(...)

You can pass any ActionScript value to this function to get a String containing its fully qualified class name.

Bitterblue
  • 13,162
  • 17
  • 86
  • 124
Jacob Wan
  • 2,521
  • 25
  • 19
9

The function is called typeof(). http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#typeof

Chiwai Chan
  • 4,716
  • 4
  • 30
  • 33
8

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

Kris Welsh
  • 334
  • 2
  • 14
5

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

spender
  • 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
2

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

Ross Attrill
  • 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