Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Flash(AS3) Unable to Remove All Children

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 glu   Members   


Posted 19 February 2013 - 06:42 PM

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
	trace(this.numChildren); //shows 0 children
	addChild(new swfLoader().loadSWF("level\\" + id.toString() + ".swf")); //class i made for loading SWF files
	trace(this.numChildren); //shows children of new level

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

#2 Jokermagician   Members   


Posted 20 February 2013 - 03:21 AM

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:


Your current loop:




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)



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


Take care!



#3 BloodyEpi   Members   


Posted 20 February 2013 - 07:25 AM

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, 20 February 2013 - 07:32 AM.

#4 stupid_programmer   Members   


Posted 20 February 2013 - 10:43 AM

As BloodyEpi already mentioned, while you are removing the graphics for your children from your scene you probably aren't removing the references to all those objects in your collision manager.  Objects in ActionScript persist until all references to that object have been removed.  If you run your game through the profiler you will probably notice your memory usage keeps going up every level change instead of staying around the same.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.