4 Replies Latest reply on May 3, 2006 6:25 PM by q9hkpz

# Copy an equal movieclip

I want to copy movieclips randomly, i.e. there are 1_mc, 2_mc, 3_mc in the scene.
Then how can I copy the movieclip with name "clip1_mc", "clip2_mc", "clip3_mc","clip4_mc","clip5_mc",......??
How can I use the "for" and "duplicate" function??
• ###### 1. Re: Copy an equal movieclip
You can use a for loop with bracket notation:

var deep = 5;
for(var i=1; i<4; i++){
var nc = this[i + "_mc"].duplicateMovieClip("clip" + i + "_mc", ++deep,
{_x:Math.random() * Stage.width, _y:Math.random() * Stage.height});
}

This will duplicate 1_mc through 3_mc to clip1_mc through clip3_mc and place
them in a random location

--
Dave -
www.blurredistinction.com
www.macromedia.com/support/forums/team_macromedia/

• ###### 2. Re: Copy an equal movieclip
quote:

Originally posted by: Newsgroup User
You can use a for loop with bracket notation:

var deep = 5;
for(var i=1; i<4; i++){
var nc = this[i + "_mc"].duplicateMovieClip("clip" + i + "_mc", ++deep,
{_x:Math.random() * Stage.width, _y:Math.random() * Stage.height});
}

This will duplicate 1_mc through 3_mc to clip1_mc through clip3_mc and place
them in a random location

--
Dave -
www.blurredistinction.com
www.macromedia.com/support/forums/team_macromedia/

Thanks,
but I have another problem,
how can I call a library object to the stage by actionscript???
thank for help

• ###### 3. Re: Copy an equal movieclip
Generally speaking there is only one problem with this proposal. It isn't a good idea to start instance names (or anything else in ActionScript) with a number. Do you have this working with "1_mc" yet? If you do, then you are very lucky.

You can only call library objects to the stage with a two step process. First right click the library entry and select "Linkage." From there you need to click the "export for actionscript" and then give the item an identifier name. Again I would recommend not starting with a number and not including any spaces.

Then you can use attachMovie to put copies of the item onto the stage. Remember that even if you end up not using the item in your code it will be exported and therefore increase the size of your swf. So at the end when you are cleaning up your project and doing the final optimizing go in and "un-linkage" any assets you ended up not using.
• ###### 4. Re: Copy an equal movieclip
quote:

Originally posted by: Rothrock
Generally speaking there is only one problem with this proposal. It isn't a good idea to start instance names (or anything else in ActionScript) with a number. Do you have this working with "1_mc" yet? If you do, then you are very lucky.

You can only call library objects to the stage with a two step process. First right click the library entry and select "Linkage." From there you need to click the "export for actionscript" and then give the item an identifier name. Again I would recommend not starting with a number and not including any spaces.

Then you can use attachMovie to put copies of the item onto the stage. Remember that even if you end up not using the item in your code it will be exported and therefore increase the size of your swf. So at the end when you are cleaning up your project and doing the final optimizing go in and "un-linkage" any assets you ended up not using.

thank for your help, i have forgetton the rules of an instance name. =.=
but could you help me checking the code??thank~
It doesn't work, but i don't know why~