Posted By

weavermedia on 11/24/10


Tagged


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

weavermedia
alptugan
tspitzr
hejaaa
mitien
MacNinja


AS3 Duplicate MovieClip with its class constructor


 / Published in: ActionScript 3
 

  1. // This is for creating a duplicate of a stage object that exists in the FLA library at compile time
  2. // The object must have a 'Export for Actionscript ticked in it's properties panel and a valid class name in the 'Class' box
  3. // If the symbol only has a single frame just add another so it registers as MovieClip() rather than Sprite()
  4.  
  5. private function cloneObject(source:DisplayObject):void
  6. {
  7. var objectClass:Class = Object(source).constructor;
  8. var instance:MovieClip = new objectClass() as MovieClip;
  9. instance.transform = source.transform;
  10. instance.filters = source.filters;
  11. instance.cacheAsBitmap = source.cacheAsBitmap;
  12. instance.opaqueBackground = source.opaqueBackground;
  13. source.parent.addChild(instance);
  14. instance.x += 20; // just to show the duplicate exists!
  15. }

Report this snippet  

You need to login to post a comment.