actionscript 3 - Flash AS3 - removeChild() used to completely delete object? -


i'm creating asteroids game , in main class i'm having trouble handling bullets ship fires.

all of bullets of "bullet" class , stored in array called "bullets" in main class. when bullets exit screen, removebullet(bulletid) in main class called.

private function removebullet(id:int)     {         removechild(bullets[id]);         bullets.splice(id);     } 

in bullet class have enterframe listener traces "stillhere". bullet added main stage using addchild, "stillhere" starts popping in output panel.

my problem after call removebullet, "stillhere" keeps popping in output panel, tells me object tried delete still sticking around somewhere in memory.

what can rid of completely?

because in actionscript have no direct control on when objects removed.

the real problem have event listeners still firing. can solve calling removeeventlistener when deleted.

however a better approach have 1 enter_frame listener whole game. need individually advance game elements (ship, asteroids, bullets, debris etc). method removes chances of accidentally forgetting remove event listeners, , makes code clearer since can see order elements update within time step.

i have destroy function in temporary objects reads this:

public function destroy():void {     stop(); // if it's movieclip     if(parent) parent.removechild(this); } 

as long call function , remove references object, it's collected.

my code has listeners on individual objects reason.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -