# Removing all instances of a displayObject

**URL:** <https://forum.kirupa.com/t/removing-all-instances-of-a-displayobject/277238>\
**Category:** flash\
**Created:** [December 9, 2008, 8:51pm UTC](https://forum.kirupa.com/t/removing-all-instances-of-a-displayobject/277238 "2008-12-09T20:51:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanderwaal](https://avatars.discourse-cdn.com/v4/letter/v/b2d939/32.png) [@vanderwaal](https://forum.kirupa.com/u/vanderwaal)\
**Post date:** [December 9, 2008, 8:51pm UTC](https://forum.kirupa.com/t/removing-all-instances-of-a-displayobject/277238/1 "2008-12-09T20:51:03Z")

</div>

i’m working on a script that creates a new instance of a movieClip each pass through a for loop and gives them a different “name”. that’s all good and fine. the trouble comes when i want to remove all of the instances of the movieClip on a button click. for some reason, clicking the button only removes the last movieClip created. i’ll be the first to admit that i’m a noob but i can’t for the life of me figure out how to remove them all instead of just the last one created.

here is the code to create the movieClips (the variable that defines specialtyContainerBox is earlier in the script)…

```auto
for (i = 0; i < specialtyData.specialty.item.length(); i++){
			specialtyArray.push(specialtyName*);
			var specialtyBoxName:String = new String('sbb' + (1+i));
			var specialtyButtonName:String = new String('sb' + (1+i));
			specialtyContainerBox = new itemContainer();
			specialtyContainerBox.name = specialtyBoxName;
			specialtyContainerBox.filters = boxFilters;
			specialtyContainerBox.x = 300+(310*xSpecialty);
			specialtyContainerBox.y = 160+(230*ySpecialty);
			if (xSpecialty+1 < columns){
				xSpecialty++;
			} else {
				xSpecialty = 0;
				ySpecialty++;
			}
			stage.addChild(specialtyContainerBox);
		}

```

in a separate function i’m trying to remove all of the instances of specialtyContainerBox with this…

```auto
stage.removeChild(specialtyContainerBox);

```

but, like i said, this only removes the last box created. i want to remove them all with one click. any ideas? is this really simple and i’m gonna wanna kick myself when i find out how to do it?
