In ActionScript3, how do you get a reference to an object's class?

actionscript-3, flash

Solution

You can use the `constructor` property if your object has been created from a class (from the docs: "If an object is an instance of a class, the constructor property holds a reference to the class object. If an object is created with a constructor function, the constructor property holds a reference to the constructor function."):

var classRef:Class = myObject.constructor as Class;

Or you can use `flash.utils.getQualifiedClassName()` and `flash.utils.getDefinitionByName()` (not a very nice way since this entails unnecessary string manipulation in the implementations of these library functions):

var classRef:Class = getDefinitionByName(getQualifiedClassName(myObject)) as Class;

Problem

In ActionScript3, how do you get a reference to an object's class?

Original source

Related problems