Clone movieclip in ActionScript3


I use BulkLoader to load MovieClips and Bitmaps into my AS3 application. Bitmaps are easy to clone, but I have some problems with complex MovieClips that have many children, buttons, characters, etc.
I found many ways to clone MovieClips as bitmaps, but is there a way to clone it as MovieClip with all its attributes?

+4
source share
2 answers

There are 2 ways:

You can copy the bootloader:

var newLoader:Loader = new Loader(); newLoader.loadBytes(oldLoader.contentLoaderInfo.bytes); 

or you can get the MovieClip class and create a new instance. But for this you will have to compile the external SWF with some document class (you do not need to create the .as file, just enter some namespace for this SWF there)

 var movieType:Class = myMovieClip.constructor; var copyMovie:MovieClip = new movieType(); 
+10
source

http://www.dannyburbol.com/2009/01/movieclip-clone-flash-as3/
http://www.smithmediafusion.com/blog/?p=446

OR

 btn1_btn.addEventListener(MouseEvent.CLICK, btnClicked); function btnClicked(e:MouseEvent):void{ var btn:MovieClip = MovieClip(e.target); //duplicate the movielcip (add a new one to the stage) var ClassDefinition:Class = Class(getDefinitionByName(getQualifiedClassName(btn))); var myMC:MovieClip = new ClassDefinition; //add it to the container myMC.x = randInt(0,260); myMC.y = 0; gravity_mc.addChild(myMC); } function randInt(min:int, max:int):int{ return Math.round(Math.random() * (max - min) + min); } 
+2
source

Source: https://habr.com/ru/post/1395181/


All Articles