Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 clone MovieClip

The below is my code for trying to clone the MovieClip and it doesn't work. We should see two cirles if the codes is working correctly.

/*The original MovieClip*/
var circle:MovieClip = new MovieClip();
circle.graphics.beginFill(0xAA0022);
circle.graphics.drawCircle(40, 40, 40);
circle.x=10
addChild(circle);

/*CLONE the MovieClip - IT DOES'T WORK FROM HERE DOWN*/
var cloneCirle:MovieClip = new MovieClip();
    cloneCirle=circle
    cloneCirle.x=60 
    addChild(cloneCirle);
like image 722
dngo Avatar asked Dec 07 '22 01:12

dngo


1 Answers

When you do cloneCircle=circle, it's not copying or cloning anything. It's just saying that the variable cloneCircle is another name for your original circle MovieClip. What you need to do is use the Graphics.copyFrom() method.

Try it:

var cloneCircle:MovieClip = new MovieClip();
cloneCircle.graphics.copyFrom(circle.graphics);
cloneCircle.x = 60;
addChild(cloneCircle);
like image 144
Mahir Avatar answered Dec 09 '22 14:12

Mahir