Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Using duplicateMovieClip

Using duplicateMovieClip

By Evgueni Strok | Published 09/9/2005 | Beginner | Rating:
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 Strok
Page 1 of 1
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
How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent

Verification:
Enter the security code shown below:
img


Add comment

Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Comments



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.