• 13
• 18
• 19
• 27
• 10

# Flash(AS3) Unable to Remove All Children

This topic is 1853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm making a game in Action Script, and I need to change levels. The current method I'm using for this, is removing all children from the first level, and then replacing them with the new children from the next level. It loads the children from the next level, and even appears to remove the ones from the first level, but it doesn't. When I move my player arround(which I shouldn't even be able to do since the player should have been deleted too), I will bump into the walls that I placed, even though the only things visible is from the new level. Here is my code for changing levels.

function changeLevel(id)
{
trace(this.numChildren); //shows all my objects

while(this.numChildren)
this.removeChildAt(0);

trace(this.numChildren); //shows 0 children

trace(this.numChildren); //shows children of new level
}


If no one posts anything, then I'll upload a video showing the problem.

##### Share on other sites

Hey there,

I have an idea about your issue, though I would urge you to take my thought with a grain of salt as I have not really done game development (though I would like to, and though I have worked with C++ and currently Java before), this may be wrong, and I haven't worked in depth with actionscript before. Still, I thought I might try to help you out if I could.

However, I looked at your while loop and had an idea. So, I searched around online for a bit and considered a few options. Here's the one I think might work best:

while(this.numChildren)
this.removeChildAt(0);

I noticed in your while loop that there is only "(this.numChildren)" instead of more of a conditional such as "(this.numChildren > 0)" or something of that matter. Maybe "(this.numChildren > 0)

this.removeChildAt(0);"

would work? I don't know. If not, sorry about that and I hope you get your answer very soon!

Take care!

--Jokermagician

##### Share on other sites

there is a method which removes all the children at once

haven't checked, but i think it may be faster since it doesn't have to decrease all the indices of the elements in the child vector after deleting the first one at index zero

but i think that your code works, the problem might be that even though you deleted all the children you still have a reference to the old level somewhere else, e.g. collisiontesting

Edited by BloodyEpi