Argh! Duplicated movieclips disappear!

Hi people!
Somehow in every game I tried to create, my duplicated movieclips dissapear as new movieclips are created. It happens randomly.
So sometimes when new duplicates are created it goes well, but other times older created movieclips dissapear.

This is the code I use:

 
onClipEvent(load) {
i = 1;
a = 1;
}
onClipEvent(enterFrame) {
rand = Math.round(Math.random()*60);
if (rand == 12) {
i++
duplicateMovieClip("_root.dummy", "dummy"+i, i);
_root["dummy" + i]._x = 660;
_root["dummy" + i]._visible = true;
}
 
Arand = Math.round(Math.random()*90);
if (Arand == 12) {
a++
duplicateMovieClip("_root.carrie", "carrie"+a, a);
_root["carrie" + a]._x = 660;
_root["carrie" + a]._visible = true;
}
}

Any help would be appreciated!! Thanks in advance!!

There can only be one movieclip in each depth. So lets say you start your application… Dummy2 is created in depth 2, Dummy3 is created in depth 3, dummy4 is created in Depth 4… now here is where your problem kicks in, when a Carrie is created, it is created in depth 2 overwriting your Dummy2 which is already in depth two. To fix this problem, try this.


onClipEvent(load) {
a = 1;
}
onClipEvent(enterFrame) {
rand = Math.round(Math.random()*60);
if (rand == 12) {
a++
duplicateMovieClip("_root.dummy", "dummy"+a,a);
_root["dummy" + a]._x = 660;
_root["dummy" + a]._visible = true;
}
 
Arand = Math.round(Math.random()*90);
if (Arand == 12) {
a++
duplicateMovieClip("_root.carrie", "carrie"+a, a);
_root["carrie" + a]._x = 660;
_root["carrie" + a]._visible = true;
}
}

Now since you are only using one increment variable, it will never repeat itself. If you must keep a count of how many of each there are, make two new variables “dummy_count” and “carrie_count” or something like that and add those every time a new one is created… just use one variable to calculate the depths though, or use getNextHighestDepth() if you are using MX04 (see MovieClip.getNextHighestDepth() documentation in the AS dictionary for more info).

Thanks man! I never even noticed that!
It works now, and I’m really glad you helped me out!

Thanks again, buddy!:thumb: