Why are my events being called more than once?

Posted by Arms on Stack Overflow See other posts from Stack Overflow or by Arms
Published on 2010-06-14T02:52:00Z Indexed on 2010/06/14 3:02 UTC
Read the original article Hit count: 290

Filed under:
|
|

In my Flash project I have a movieclip that has 2 keyframes. Both frames contain 1 movieclip each.

frame 1 - Landing
frame 2 - Game

The flow of the application is simple:

  1. User arrives on landing page (frame 1)
  2. User clicks "start game" button
  3. User is brought to the game page (frame 2)
  4. When the game is over, the user can press a "play again" button which brings them back to step 1

Both Landing and Game movieclips are linked to separate classes that define event listeners. The problem is that when I end up back at step 1 after playing the game, the Game event listeners fire twice for their respective event. And if I go through the process a third time, the event listeners fire three times for every event. This keeps happening, so if I loop through the application flow 7 times, the event listeners fire seven times. I don't understand why this is happening because on frame 1, the Game movieclip (and I would assume its related class instance) does not exist - but I'm clearly missing something here.

I've run into this problem in other projects too, and tried fixing it by first checking if the event listeners existed and only defining them if they didn't, but I ended up with unexpected results that didn't really solve the problem.

I need to ensure that the event listeners only fire once. Any advice & insight would be greatly appreciated, thanks!

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3