PDA

View Full Version : How to duplicate moveclip automatically?



nanny
September 8th, 2003, 10:12 PM
Hello,

In my flash file, I have a movieclip called target and one button used to
duplicate the target movieclip.


the actionscript of movieclip is

onClipEvent (load) {

scale = (random(100) + 50)

this._x = random(550);
this._y = random(400);
this._alpha = random(100);
this._xscale = scale;
this._yscale = scale;

}



the actionscript of button is
i = i + 1;
duplicateMovieClip (_root.target, "target" + i, i);


I would like to duplicate movieclip(target) automatically means I don't have to press button to duplicate movieclip.


Any ideas?

I am really appreciate your help.

Yeldarb
September 8th, 2003, 10:43 PM
in the movieclips as add the code that you have in the button to the load event, this will create one new movieclip every frame (i think this is what you want...)
or if you want it to occur less often, generate a random number, and have it only duplicate when that number = 1

Voetsjoeba
September 9th, 2003, 12:41 PM
Use a for loop:

for(i=0;i<=20;i++){
duplicateMovieClip (_root.target, "target" + i, i);
}

Where 20 is the amount of times it will duplicate. Seems to me you want to generate a random field of "targets" on button press. Then use this: (on the main timeline)


button.onRelease = function(){
for(i=0;i<=20;i++){
duplicateMovieClip (_root.target, "target" + i, i);
mc = _root["target"+i];
mc._x = random(550);
mc._y = random(400);
mc._alpha = random(100);
mc._xscale = mc._yscale = Math.round((Math.random()*100)+50);
}
}