PDA

View Full Version : Getting an instance's main class



IQAndreas
July 21st, 2009, 02:01 PM
Say I have a variable that contains an instance of a class. Is there any way to return a "Class" object based on what type that variable is?

I wish there was something like this:

var button:SimpleButton = new SimpleButton();
this.addChild(duplicate(button));

function duplicate(target:Object):Object
var mainClass:Class = target.baseClass; //Yes, I know the "baseClass" function doesn't exist. This is what I want.
var cloneObj:Button = new MainClass();
return cloneObj;
}

I am able to extract the class name in text format, and even all items that it extends and interfaces, yet I cannot find any way to create a class based on

I did find the function "getDefinitionByName()" and "getClassByAlias()", but if I understand correctly, you have to first register those definitions.

Also, is it possible to extract usable Classes (not just display objects) out of externally loaded SWFs?

senocular
July 21st, 2009, 02:11 PM
http://livedocs.adobe.com/flex/3/langref/Object.html#constructor


Also, is it possible to extract usable Classes (not just display objects) out of externally loaded SWFs?

through an application domain
http://livedocs.adobe.com/flex/3/langref/flash/display/LoaderInfo.html
http://livedocs.adobe.com/flex/3/langref/flash/system/ApplicationDomain.html
http://livedocs.adobe.com/flex/3/langref/flash/system/ApplicationDomain.html#getDefinition()