# \[FLASH 8\] How do I duplicate movieclips and make them keep code?

**URL:** <https://forum.kirupa.com/t/flash-8-how-do-i-duplicate-movieclips-and-make-them-keep-code/328781>\
**Category:** flash\
**Created:** [June 16, 2012, 4:07am UTC](https://forum.kirupa.com/t/flash-8-how-do-i-duplicate-movieclips-and-make-them-keep-code/328781 "2012-06-16T04:07:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mablargy](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mablargy](https://forum.kirupa.com/u/Mablargy)\
**Post date:** [June 16, 2012, 4:07am UTC](https://forum.kirupa.com/t/flash-8-how-do-i-duplicate-movieclips-and-make-them-keep-code/328781/1 "2012-06-16T04:07:55Z")

</div>

Hey guys, I’m having a little trouble here… I’m trying to duplicate a movieclip when a button is clicked, but I want the movieclip that’s being duplicate to keep the same code and properties as the one it’s duplicating.

For example, the movieclip being duplicated is a little ball that attracts other ball movieclips, sort of like gravity, but I would like to see what would happen if multiple of these where on the stage, so I have this set up:

```auto

dupGravity = function()
{
    for(i=0; i<gravlimit; i++){
        gravity_mc.duplicateMovieClip("gravity"+i, i, {_x:200, _y:200})
    }
}

button_mc.onRelease = dupGravity;

//
//The following code just makes the Ball of Gravity attract the other balls
//

_root.gravity_mc.onEnterFrame = function() 
{
    
    if (xspeed>=xlimit)
{
    xspeed=xlimit;
}
if (yspeed>=ylimit)
{
    yspeed=ylimit;
}
    if(gravity_mc._y>=ball_mc._y)
    {
        yspeed-=gravity;
        ball_mc._y+=yspeed;
    }
    else
    {
        yspeed+=gravity;
        ball_mc._y+=yspeed;
    }
    if(gravity_mc._x>=ball_mc._x)
    {
        xspeed-=gravity;
        ball_mc._x+=xspeed;
    }
    else
    {
        xspeed+=gravity;
        ball_mc._x+=xspeed;
    }

```

I was wondering if you guys could help me out. I mean the gravity duplicates right where I want it to, but it doesn’t do anything like the original, it doesn’t attract other objects, it can’t be dragged, etc. Any help would be greatly appreciated 😃
