
Page 1 of 1
Evgueni Strok
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by Evgueni StrokDifficulty Level: Beginner
Requirements: Flash 5 or higher
duplicatemovieclip creates a copy of a movie clip specified using an instance name.
I think the best way to understand how it works is to start from a very basic example and step by step we'll try to add some new lines of code.
EXAMPLE 1
To duplicatemovieclip we need a Movie Clip (MC) which will be duplicated.
In my example I made a MC_1 with Instance name "box"

I'll call a duplicatemovieclip function by using button with this script on it:
on (release) {
duplicatemovieclip ("box", "box2", 1);
}
box -- Instance name of MC which is suppose to be duplicated
box2 -- name for duplicated MC
Download FLA
The duplicated MC inherits the _x and _y coordinates of the clip it is copied from, so it will appear above the original but we can move this using a setProperty action. See example below.
EXAMPLE 2
Download FLA
on (release) {
duplicatemovieclip("box", "box2", 1);
setProperty ("box2", _x, "200");
}
This same code could also be written as:
on (release) {
_root.box.duplicatemovieclip("box2", 1);
box2._x=200;
}
EXAMPLE 3
This example duplicates an MC 20 times using a while loop. See the Scripted Loops tutorial for more on loops, and the Advanced Pathing tutorial for more on the strange paths used in this example.
Download FLA
on (release) {
count = 1;
while (count<20) {
_root.box.duplicatemovieclip("boxx"+count, count);
count += 1;
}
}
The next example duplicates an MC 20 times and uses "random" properties for each duplicated MC. Thus each new MC will get a random _x, _y, _xscale, _xscale positions and _alpha properly.
EXAMPLE 4
Download FLA
on (release) {
count = 1;
while (count<20) {
_root.box.duplicatemovieclip("boxx"+count, count);
_root["boxx"+count]._x = random(550);
_root["boxx"+count]._y = random(150);
_root["boxx"+count]._xscale = random(150);
_root["boxx"+count]._yscale = random(150);
_root["boxx"+count]._alpha = random(100);
count += 1;
}
}
Note: If you reuse the same Instance name for duplicated MC you'll replace the old one. The above code creates a new unique instance name each time using a counter.
EXAMPLE 5
This example has the same actionscript which has been added on frame.
And a MC has a small timeline.
Download FLA
Spread The Word
Related Articles
13 Responses to "Using duplicateMovieClip" 
|
said this on 12 Feb 2009 1:59:55 PM CDT
Excelllent. All needed in
|
|
said this on 06 Jul 2009 4:09:04 PM CDT
When I duplicate a moviec
|
|
said this on 17 Feb 2010 4:15:15 AM CDT
This tutorial is a very g
|
|
said this on 27 Mar 2010 4:02:09 AM CDT
Simply great man !!
|
|
said this on 04 Jul 2010 1:36:14 PM CDT
I like very much this mov
|
|
said this on 04 Jul 2010 1:37:41 PM CDT
It is excellent, to see t
|
|
said this on 13 Sep 2010 10:46:38 PM CDT
Excellent and thanks
|
|
said this on 23 Sep 2010 7:14:40 PM CDT
This was a great tutorial
|
|
said this on 25 Nov 2010 11:10:54 PM CDT
its great i think we can
color = new Color G |
|
said this on 10 Nov 2011 12:48:43 PM CDT
I can't figure it out. Wh
if (t1 duplicateMovi s setProperty (e } t1 always equals 15. |


Author/Admin)
