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

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:



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 :smiley: