Removeing event listeners

Hi,

 1st : Is it ok if I don’t remove my events listeners? If I don’t remove them what could go wrong with my game?

 2nd : If I purge the current level,will I be able for the player to bring it back,when he taps a button on the game?

Thanks!

There are a couple of different kinds of event listeners.  Those that are attached to objects and those that are attached to the app in general.   Generally those attached to objects, like touch, tap and collision listeners, go away with the object when the object is destroyed.  If the object is moved off screen, then the user can’t interact with it so there is no need to remove it.

Other event listeners like Runtime enterFrame listeners run every 1/30th or 1/60th of a second.  If you don’t remove them, they keep running and running.  If objects that function refers too go away, your app will crash.  Other event listeners, like key listeners, system listeners and such can be removed if you need to, but in general, they don’t hurt to leave running.

Rob

Can I also add that if you add a listener, don’t remove it, and then add it again it will be running twice each frame. 

So potentially you could add an enterFrame listener for your game, and then on reloading the level add it a second time which could really slow down your app, not to mention cause you confusion.

There are a couple of different kinds of event listeners.  Those that are attached to objects and those that are attached to the app in general.   Generally those attached to objects, like touch, tap and collision listeners, go away with the object when the object is destroyed.  If the object is moved off screen, then the user can’t interact with it so there is no need to remove it.

Other event listeners like Runtime enterFrame listeners run every 1/30th or 1/60th of a second.  If you don’t remove them, they keep running and running.  If objects that function refers too go away, your app will crash.  Other event listeners, like key listeners, system listeners and such can be removed if you need to, but in general, they don’t hurt to leave running.

Rob

Can I also add that if you add a listener, don’t remove it, and then add it again it will be running twice each frame. 

So potentially you could add an enterFrame listener for your game, and then on reloading the level add it a second time which could really slow down your app, not to mention cause you confusion.