Reputation: 408
I have a pretty complex game with many views and many controllers, and it works really well but periodically lags. I am trying to fix up my code so it's as efficient as i can make it, but i have some questions as to who AS3 handles events.
Now here is a very basic example:
AppController loads 5 different OverlayControllers. Each one of those OverlayControllers dispatch an Event.COMPLETE when they are done that my AppController listens to. I have a constant EventListener listening to those OverlayControlllers no matter where I am in the game.
Should i only have those listeners there when the Overlay is open? And Remove them when they close?
Should i bypass the event listener period and just pass the AppController to the OverlayControllers so it can just call a public function instead of requiring an EventListener?
Just to be clear these aren't objects that i'm removing from the stage. They are just being hidden. If i ever remove an object i always remove its event listeners before destroying them.
Upvotes: 1
Views: 54
Reputation: 1268
First of all download Adobe Scout (http://www.adobe.com/devnet/scout/articles/adobe-scout-getting-started.html) and see what's causing the "lags" - probably garbage collection ...then fix the issue. Removing as many listeners as possible is always a good thing but make sure that those are causing the issue. Profile memory usage and try to keep object creation/destruction to a minimum to avoid garbage collection (during the main game loop).
Upvotes: 1