Written by: Evgueni Strok
Difficulty 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