For Level Master 2000, I needed two functions:
- getClass, which I stuff in any kind of object, and it returns me its class.
- getSuperClass, which I stuff in it’s class name as string, and it returns me the class name of its parent as string.
Note that first returns the class itself, and the second one works with strings. If you need to e.g. let the second one work with classes also, just adapt it like in the first function.
All in all, you need to import these functions:
import flash.utils.getDefinitionByName; import flash.utils.getQualifiedClassName; import flash.utils.getQualifiedSuperclassName;
And here are the two functions:
public static function getClass(obj:Object):Class { return Class(getDefinitionByName(getQualifiedClassName(obj))); }
static public function getSuperClass(className:String):String { return getQualifiedSuperclassName(getDefinitionByName(className)); }
Note that getSuperClass only returns its direct parent. If you need to go further up the inheritance tree, you need to call it recursively. Highest it can get is “Object”.