<p>How do you get an instance of the actionscript class <code>Class</code> from an instance of that class?</p>

<p>In Python, this would be <code>x.__class__</code>; in Java, <code>x.getClass();</code>.</p>

<p>I'm aware that <a href="http://actionscript.org/forums/showthread.php3?t=120135#td_post_545693" rel="noreferrer">certain terrible hacks</a> exist to do this, but I'm looking for a built-in language facility, or at least a library routine built on something reliable.</p>

Any reason you couldn't do this?
```
```
var s:Sprite = new flash.display.Sprite();

var className:String = flash.utils.getQualifiedClassName( s );
var myClass:Class = flash.utils.getDefinitionByName( className ) as Class;

trace(className ); // flash.display::Sprite
trace(myClass); // [class Sprite]

var s2 = new myClass();
trace(s2); // [object Sprite]
```
```
I don't know a way to avoid round-tripping through a String, but it should work well enough.