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?
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();
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With