How do I get from an instance of a class to a Class object in ActionScript 3?

Glyph picture Glyph · Oct 15, 2008 · Viewed 22.9k times · Source

How do you get an instance of the actionscript class Class from an instance of that class?

In Python, this would be x.__class__; in Java, x.getClass();.

I'm aware that certain terrible hacks exist to do this, but I'm looking for a built-in language facility, or at least a library routine built on something reliable.

Answer

Gerald picture Gerald · Oct 15, 2008

You can get it through the 'constructor' property of the base Object class. i.e.:

var myClass:Class = Object(myObj).constructor;