# Reliable Remove Child Method

**URL:** <https://forum.kirupa.com/t/reliable-remove-child-method/260347>\
**Category:** flash\
**Created:** [May 14, 2008, 4:36pm UTC](https://forum.kirupa.com/t/reliable-remove-child-method/260347 "2008-05-14T16:36:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![veniceflasher](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@veniceflasher](https://forum.kirupa.com/u/veniceflasher)\
**Post date:** [May 14, 2008, 4:36pm UTC](https://forum.kirupa.com/t/reliable-remove-child-method/260347/1 "2008-05-14T16:36:30Z")

</div>

Hello,

I’m new here. Mostly a design person. I’m struggling with removing externally loaded movies. I have a series of externally loading SWFs. On a button click Each movie reduces its alpha to zero, loads the next or previous movie, then unloads itself. I’ve tried putting the removeChild(this) code in a function, on its own line etc. The code works 2 or 3 times then the movies no longer remove themselves and just pile up. Is it unwise to to have a series of movies that load each other and remove themselves from the stage? Each movie has the same exact code for its previous and next buttons… Help! Here’s the code:

nextButt.addEventListener(MouseEvent.MOUSE\_DOWN, nextCase);

function nextCase(event:MouseEvent):void{

```
var nextAplhaTween_1:Tween = new Tween(this, "alpha", Regular.easeIn, 1, 0, 2, true);

// load new movie
var caseDisplay_3:MovieClip;
var caseLoader:Loader = new Loader();
caseLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded, false, 0, true);
caseLoader.load(new URLRequest("case_3.swf"));

function loaded(evt:Event):void {
	caseDisplay_3 = MovieClip(caseLoader.content);
	caseDisplay_3.x = 165;
	caseDisplay_3.y = 160;
	stage.addChild(caseDisplay_3);
}

MovieClip(this.parent).removeChild(this);

```

}

---

<div class="post-metadata">

**Author:** ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)\
**Post date:** [May 15, 2008, 1:16am UTC](https://forum.kirupa.com/t/reliable-remove-child-method/260347/2 "2008-05-15T01:16:54Z")

</div>

is that loaded function inside the nextCase function?  
anyway, if you are just adding it to the stage, why dont you just use stage.removeChild()?

---

<div class="post-metadata">

**Author:** ![veniceflasher](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@veniceflasher](https://forum.kirupa.com/u/veniceflasher)\
**Post date:** [May 15, 2008, 3:42pm UTC](https://forum.kirupa.com/t/reliable-remove-child-method/260347/3 "2008-05-15T15:42:58Z")

</div>

[QUOTE=johnlouis;2326409]is that loaded function inside the nextCase function?  
anyway, if you are just adding it to the stage, why dont you just use stage.removeChild()?[/QUOTE]

Yeah it is inside the nextCase function. I think my basic problem was having this series of external SWFs load the next in series and then unload itself. They would sometimes work and sometimes not unload themselves. I’m thinking that was not the right approach so I’m putting the buttons that do the loading and unloading in the main movie. Now its a matter of getting strings that get updated to function adequately as instance names…

Thanks for the response!
