Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone movieclip in ActionScript3


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?

like image 571
Mikhail Avatar asked Dec 17 '22 04:12

Mikhail


2 Answers

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();
like image 81
turbosqel Avatar answered Dec 28 '22 02:12

turbosqel


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);
}
like image 33
Swati Singh Avatar answered Dec 28 '22 03:12

Swati Singh