Returns a new object of the same Class


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.