Ok, I’m pulling a Clip out of the Library and Duplicating it so many times with this code. It works fine. I would like to know what the best way to remove them all at once is, and also to be able to click a button and have the number that is duplicated on the stage change. I’ve tried a couple of ways for that but can’t quite get it to work. A little help is appreciated. Thanks.
if you are using attachMovie anyway, it is a little pointless to duplicate
try this
_global.amount = 100;
createEmptyMovieClip(“paper”, 1);
for (i=0; i<_global.amount; i++) {
clip = paper.attachMovie(“Ball”, “ball”+i, i);
clip._xscale = clip._yscale=(random(75));
clip._x = random(500);
clip._y = random(350);
}
There was no need to create the empty movieclip but it just makes it easier to remove all the mcs. You can either just use paper.removeMovieClip()
or
for (childMC in paper) {
if (typeof (paper[childMC]) == “movieclip”) {
removeMovieClip(paper[childMC]);
}
}
There is also no need to keep referencing _global unless you want to change amount from a different timeline.
Thanks Stringy, that code seems to work great. I have another question. What if I want to have a button on another timeline change the amount of attached movie clips? For instance I started with 100, and I want to change it to only 50 when a button is released and to 150 when a different button is released. BTW, that is why I was using _global, because I will be referencing it from another timeline. Thanks.
you could just make it a function
on the main timeline
createEmptyMovieClip(“paper”, 1);
_global.makeStuff = function(amount) {
for (i=0; i<amount; i++) {
clip = paper.attachMovie(“Ball”, “ball”+i, i);
clip._xscale = clip._yscale=(random(75));
clip._x = random(500);
clip._y = random(350);
}
};
I actually prefer to code from the maintimeline but the _global bit makes this accessible to anytimeline
So on a button on anytimeline
on (release) {
makestuff(20);
}
Edit/forgot to remove
createEmptyMovieClip(“paper”, 1);
_global.makeStuff = function(amount) {
for (childMC in paper) {
if (typeof (paper[childMC]) == “movieclip”) {
removeMovieClip(paper[childMC]);
}
}
for (i=0; i<amount; i++) {
clip = paper.attachMovie(“Ball”, “ball”+i, i);
clip._xscale = clip._yscale=(random(75));
clip._x = random(500);
clip._y = random(350);
}
};
if you wanted to keep adding clips you could createEmptymovieclips inside the function
If I click button 2, it creates 500 movie clips. But if I click button 1 after that, it resets 20 of the clips and replaces them randomly but there are still 500 clips. I want it to clear all the movie clips except for 20 by clicking button 1. Hope I explained that clearly. Thanks.