Skip to main content
Inspiring
December 6, 2007
Answered

Duplicating Movie Clips

  • December 6, 2007
  • 2 replies
  • 300 views
Hello,

I this is probably a very simple thing to do but I cant find anything which seems to a duplicate movie clip and maybe this function has been completely removed and not recreated at all within the new AS3 where it was available in AS2.

I am wondering if someone can help me with this.

I have attached a snippet of my code below which defines what I am attempting, any help would be appreciated.

Basically all I want to do is duplicate a movieclip in a for loop and have them placed side by side with each other.

Here is my code:

for (i=0; i<10; i++)
{
addChild (_brick);
_brick.x = brick.width * i;
}

Many thanks in advance

Lee
This topic has been closed for replies.
Correct answer BSpero-9w1iVb
Lee,
You have to assign each new brick to an instance, then add that child to the stage. There may be a more proper coding way to do it, but based on your code, you would need to turn on linking of your brick movie clip and make sure it's named "_brick". Then, this should work.

for (var i=0; i<10; i++) {
var myBrick = new _brick();
addChild(myBrick);
myBrick.x = myBrick.width * i;
}

2 replies

Inspiring
December 6, 2007
You Legend!!!

Thanks so much for your help. It has taken me hours and hours and I have been gettin no where.

I kinda had an idea I had to recreate a new instance but I did not know if I would have to give each instance dymanically generated names etc for them to work, but your simple solution has worked perfectly.

Thanks again,

Lee
BSpero-9w1iVbCorrect answer
Inspiring
December 6, 2007
Lee,
You have to assign each new brick to an instance, then add that child to the stage. There may be a more proper coding way to do it, but based on your code, you would need to turn on linking of your brick movie clip and make sure it's named "_brick". Then, this should work.

for (var i=0; i<10; i++) {
var myBrick = new _brick();
addChild(myBrick);
myBrick.x = myBrick.width * i;
}