/ Published in: ActionScript 3
This function returns a new instance of the class it receives.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import flash.utils.getDefinitionByName; import flash.utils.getQualifiedClassName; public function getNewClassInstance(object:*):*{ var className:String = getQualifiedClassName(object); var classReference:Class = getDefinitionByName(className) as Class; var newClassInstance:* = new classReference(); // e.g. object is from the class MovieClip trace(newClassInstance); // [object MovieClip] trace(className); // flash.display::MovieClip trace(classReference); // [class MovieClip] return newClassInstance; }