# AS2 - Remove all movieclip instances

**URL:** <https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281>\
**Category:** flash\
**Created:** [May 25, 2008, 5:16pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281 "2008-05-25T17:16:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noahdecoco](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Noahdecoco](https://forum.kirupa.com/u/Noahdecoco)\
**Post date:** [May 25, 2008, 5:16pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/1 "2008-05-25T17:16:53Z")

</div>

Hello! Good day to you!!!

Could you help me with something please? Is there a code to remove all instances of a particular movieclip on stage? The code

removeMovieClip(target);

removes just one particular instance. That wont do for me at all! I need to remove all the instances. How do I do that?

Thank you!!! Have a good day!

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [May 25, 2008, 5:35pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/2 "2008-05-25T17:35:56Z")

</div>

if all your clips are on the same time timeline - lets say they’re in a clip named “holder”, and all your clips are named with the prefix “foo\_”:

one way::

```auto

for(var i in holder) {
    if(typeof(holder*)=="movieclip" && holder*._name.substr(0,4)=="foo_") {
           // if you're clips are not dynamically attached, then de-comment this line:
           //holder*.swapDepths(10000);
           holder*.removeMovieClip();
    }
}

```

---

<div class="post-metadata">

**Author:** ![Noahdecoco](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Noahdecoco](https://forum.kirupa.com/u/Noahdecoco)\
**Post date:** [May 25, 2008, 6:00pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/3 "2008-05-25T18:00:06Z")

</div>

I didn’t really understand that code… Hmmm, all my instances aren’t placed in another clip… they are all on the time line… if they were in another clip, maybe i would just unload that clip all together…

I can’t put them all in one other clip because each instance has a code to drag its parent, so i guess that would mean that all of them would get dragged together right?

Thanks for your help! You said that that was one way… Is there another way? Greatly appreciate it!

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 25, 2008, 6:06pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/4 "2008-05-25T18:06:17Z")

</div>

name your moviclips as mc1 mc2 mc3 etc: either by code or manually.  
then for removing all… use

for(var i=0;i\<noOfclips;i++)  
{  
var clip=\_root[“mc”+i];  
clip.removeMovieClip();  
}

[quote=Noahdecoco;2330962]I didn’t really understand that code… Hmmm, all my instances aren’t placed in another clip… they are all on the time line… if they were in another clip, maybe i would just unload that clip all together…

I can’t put them all in one other clip because each instance has a code to drag its parent, so i guess that would mean that all of them would get dragged together right?

Thanks for your help! You said that that was one way… Is there another way? Greatly appreciate it![/quote]

---

<div class="post-metadata">

**Author:** ![JBPresents](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@JBPresents](https://forum.kirupa.com/u/JBPresents)\
**Post date:** [May 25, 2008, 7:22pm UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/5 "2008-05-25T19:22:44Z")

</div>

you could also just plop them all into a single movieclip

instead of all in the \_root timeline plop them into a movie clip that you could then kill whenever you wanted

---

<div class="post-metadata">

**Author:** ![Noahdecoco](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Noahdecoco](https://forum.kirupa.com/u/Noahdecoco)\
**Post date:** [May 26, 2008, 3:10am UTC](https://forum.kirupa.com/t/as2-remove-all-movieclip-instances/261281/6 "2008-05-26T03:10:19Z")

</div>

Hey, thanks man… it worked fine! Right now I’m hardcoding the number of movieclips to 1000, but in the future, I’ll make a counter to count each movie clip as it gets loaded so that at the end I know exactly how many there are…

Nice code! Works fine!
