Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionscript 3 - Completely removing a child

I have an array of objects that when another object hits one of them, the object will be removed. I have removed it from the stage using removeChild() and removed from the array using splice(), but somehow the object is still calling some of its functions which is causing errors. How do I completely get rid of an object? There are no event listeners tied to it either.


2 Answers

You need to make sure that the display object you're removing:

  • has no listeners registered on the stage, e.g. you need to call stage.removeEventListener(...) for any corresponding stage.addEventListener(...)
  • doesn't have a listener for the Event.ENTER_FRAME event
  • doesn't listen for events on any timers
  • isn't called by a timer set up with setInterval anywhere
  • etc. basically anything having to do with timers, the stage, it's parent, loaders and the time line can cause objects to linger and not be removed

So when you have removed the object with removeChild and removed it from the array you kept it in, also call its stop method to make sure it's not playing its timeline. It may also be a good thing to have a method on that object called something like halt, cleanup or finalize that unregisters any listeners, stops timers, timeouts, intervals, etc., clears references (i.e. sets the variables to null) to it's parent, the stage or any object that isn't going away too.

like image 52
Theo Avatar answered Apr 27 '26 08:04

Theo


It sounds like you may be running into a garbage collection issue with the flash player.

A new API has been added to Flash Player 10 that should address this:

unloadAndStop()

Grant Skinner has more info on this on his blog: http://www.gskinner.com/blog/archives/2008/07/unloadandstop_i.html

You can grab a beta of Flash Player 10 at:

http://labs.adobe.com/technologies/flashplayer10/

mike chambers

[email protected]

like image 38
mikechambers Avatar answered Apr 27 '26 07:04

mikechambers