I'm using BulkLoader to load MovieClips and Bitmaps into my AS3 app. Bitmaps are easy to clone, but I have some problems with complicated MovieClips, which has many children, buttons, symbols, etc.
I've found many ways to clone MovieClips as Bitmaps, but is there a way to clone it as MovieClip, with all its attributes?
Asked
Active
Viewed 4,624 times
4

Mikhail
- 759
- 2
- 9
- 26
2 Answers
10
there are 2 ways :
You can copy Loader :
var newLoader:Loader = new Loader();
newLoader.loadBytes(oldLoader.contentLoaderInfo.bytes);
or You can get MovieClip class and create new instance of it . But for this You will have to compile external SWF with some document class (You dont have to create .as file , just type there some namespace for this SWF)
var movieType:Class = myMovieClip.constructor;
var copyMovie:MovieClip = new movieType();

turbosqel
- 1,542
- 11
- 20
-
I'd also consider simply loading the clip to be cloned multiple times, it will hit the browser cache for every subsequent load and it won't require any black voodoo magic trickery. – grapefrukt Feb 07 '12 at 09:48
-
@ grapefrukt, I tried your method a long time ago, its only practical to load a couple of files but if you have say 30 copies , when loading the screen will pause still for the same amount of time as actually loading them, but my percentage text will read %100 – joshua Mar 26 '13 at 14:02
-
@ turbosqel, Thanks that was 10 times easier, – joshua Mar 26 '13 at 14:08
-
Best method is create new instance of existing class (2nd way) , fast , synchronius and take less memory . – turbosqel Mar 26 '13 at 15:32
2
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);
}

Swati Singh
- 1,863
- 3
- 19
- 40