# removeChild from for-loop problem

**URL:** <https://forum.kirupa.com/t/removechild-from-for-loop-problem/262827>\
**Category:** flash\
**Created:** [June 10, 2008, 11:30am UTC](https://forum.kirupa.com/t/removechild-from-for-loop-problem/262827 "2008-06-10T11:30:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Macleod](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Macleod](https://forum.kirupa.com/u/Macleod)\
**Post date:** [June 10, 2008, 11:30am UTC](https://forum.kirupa.com/t/removechild-from-for-loop-problem/262827/1 "2008-06-10T11:30:51Z")

</div>

Hi everyone.

I am trying to get a grip of as3 by converting one of my ongoing projects from as2, but it’s really giving me a bit of a headache. I am more of a designer than a developer, so I need help with something that’s probably pretty basic for you guys.

Here is my problem:

I am making a multilanguage company presentation for a company (air-application). The users choose their prefered language from a menu, which then sets up the correct menu, loaded from xml. I do this with a for loop:

for (i = 0; i\<xmlData.name.length(); i++) {

var myBtn:bt\_mc = new bt\_mc();  
addChild(myBtn).name = “myBtn” + i;  
myBtn.y = 20 + i\*(myBtn.height);  
myBtn.x = 20;  
myBtn.width = 180;  
myBtn.buttonMode = true;  
myBtn.mouseChildren = false;  
myBtn.addEventListener(MouseEvent.MOUSE\_DOWN,onpress)  
myBtn.addEventListener(MouseEvent.ROLL\_OVER,onroll)  
myBtn.addEventListener(MouseEvent.ROLL\_OUT,onrollout)  
var textPath:String = xmlData.name\*.text();  
myBtn.textfield.text = textPath;  
}

So far so good. Menu sets up perfectly.  
The problem is that I need to “reset” the menu before running the loop again when I choose another language from the language menu, as it wont replace the buttons allready generated in the lool, as it would with as2 attachMovie.

Any ideas anyone?
