flash - Why are my event listeners firing more than once? -


In my flash project I have a movie clip that has 2 keyframes, both frames have 1 movie clip.

Frame 1 - Landing
frame2 - game

User is simple:

  1. User clicks on the landing page (frame 1) / Li>
  2. When the game is over, the user can press a "play again" button which brings them back to step 1

both landing < / Code> and games movieclips separate C is attached to the classes that define event listeners. The problem is that when I come back to step 1 after playing the game, game event listeners fire twice for their respective event. And if I go through this process for the third time, event listeners set fire to three incidents for three occasions. It keeps happening, so if I loop through the application flow 7 times, the incident listener gets a fire seven times, I do not understand why this is happening because the frame 1, game < / Code> movie clips (and I will accept its corresponding class example) does not exist - but I have clearly forgotten something here.

I have also participated in other projects in this problem, and tried first to check whether the event listener is present and only define them if they do not, but I Unexpected results were found which were not really the solution to the problem.

I need to make sure that event listeners will only get a fire. Any advice & amp; Insight will be greatly appreciated thanks!

If you have two frames with separate clips on the same layer, every time the "frame" ", Then that clip is made. When this "Leaves" clip is removed, but it will still be kept around and the garbage will not be collected. So next time the frame enters a different clip, it is "made" and it gets its listener. Your best bet is to remove the listeners when you change the frame. I usually get around such things by becoming a listener for each category in the Event.REMOVED_FROM_STAGE . If it has been removed, you can clear the remaining audience.

You may also want to experiment with "weak listeners":

EVENTListener (GameEvent .GAME_START, game starred handler, wrong, 0, true);

Creates the "right" link "weak", so if an object is removed, the garbage collector can choose it. I will not trust it completely though. It is better to remove the references manually so that you can be sure.

This answer takes a lot of courses. If you post code / screenshots / flaws for better diagnosis, then it will be helpful.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -