Skip to main content
Known Participant
November 11, 2009
Question

AS3 duplicate a movie clip that exists on stage

  • November 11, 2009
  • 1 reply
  • 5400 views

I'm using AS3 in timeline. I'm trying to duplicate a movie clip that exists on stage. I'm unsuccessfully using the following code:

name of movie clip on stage = ball_mc

var i:Number = 2; //it will be the total number of circles
function makeACircle(e:Event):void {
ball_mc.x = Math.random () *400;
ball_mc.y = Math.random () *250;
i++;
}

Please help me figure out how to duplicate a movie clip not using its class name.

German

This topic has been closed for replies.

1 reply

November 11, 2009

The code you show would just move the existing clip to a random spot. I'm not sure how you'd duplicate a clip without using its class name - and why do you not want to use its class - it's the proper way - and quite simple.

If in your library you have a circle clip - give it a class name of something like myCircle

Then all you do in your code is say:

function dupCircle(){

     var circ = new myCircle();

     circ.x = Math.random () *400;
      circ.y = Math.random () *250;

     addChild(circ);

}

You can call that as much as you need.

german01Author
Known Participant
November 11, 2009

Thanks dmennenoh

I knew how to use the class function. I just wondered if I could duplicate a movie clip that existed on stage. I appreciated your answer.

German