# Argh! Duplicated movieclips disappear!

**URL:** <https://forum.kirupa.com/t/argh-duplicated-movieclips-disappear/119242>\
**Category:** Uncategorized\
**Created:** [August 12, 2004, 7:31pm UTC](https://forum.kirupa.com/t/argh-duplicated-movieclips-disappear/119242 "2004-08-12T19:31:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferdi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ferdi/32/689_2.png) [@Ferdi](https://forum.kirupa.com/u/Ferdi)\
**Post date:** [August 12, 2004, 7:31pm UTC](https://forum.kirupa.com/t/argh-duplicated-movieclips-disappear/119242/1 "2004-08-12T19:31:26Z")

</div>

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:

```auto
 
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!!

---

<div class="post-metadata">

**Author:** ![APDesign](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@APDesign](https://forum.kirupa.com/u/APDesign)\
**Post date:** [August 12, 2004, 8:26pm UTC](https://forum.kirupa.com/t/argh-duplicated-movieclips-disappear/119242/2 "2004-08-12T20:26:26Z")

</div>

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.

```auto

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).

---

<div class="post-metadata">

**Author:** ![Ferdi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ferdi/32/689_2.png) [@Ferdi](https://forum.kirupa.com/u/Ferdi)\
**Post date:** [August 12, 2004, 8:35pm UTC](https://forum.kirupa.com/t/argh-duplicated-movieclips-disappear/119242/3 "2004-08-12T20:35:35Z")

</div>

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

Thanks again, buddy!:thumb:
