Posted By

JaaQ on 02/03/11


Tagged

class object new copy getDefinitionByName getQualifiedClassName


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

shuchii
weavermedia
pepperpunk


Returns a new object of the same Class


 / Published in: ActionScript 3
 

This function returns a new instance of the class it receives.

  1. import flash.utils.getDefinitionByName;
  2. import flash.utils.getQualifiedClassName;
  3.  
  4. public function getNewClassInstance(object:*):*{
  5.  
  6. var className:String = getQualifiedClassName(object);
  7. var classReference:Class = getDefinitionByName(className) as Class;
  8. var newClassInstance:* = new classReference();
  9.  
  10. // e.g. object is from the class MovieClip
  11.  
  12. trace(newClassInstance); // [object MovieClip]
  13. trace(className); // flash.display::MovieClip
  14. trace(classReference); // [class MovieClip]
  15.  
  16. return newClassInstance;
  17. }

Report this snippet  

You need to login to post a comment.