Events (e.g. MouseEvent.CLICK) Counting twice...how to clear?

Subscribe to Events (e.g. MouseEvent.CLICK) Counting twice...how to clear? 8 posts, 6 voices

Sign in to reply


 
avatar for NeoClassic NeoClassic 8 posts
Flag Post

Is there a way to clear an event or otherwise notify flash that it’s been handled already?

One problem I’m running into is the following:

From the main menu, a single click takes the user to the instructions screen.
Once on that screen, a click takes the user back to the menu.

However, the problem I’m having is that a single click quickly shows and then hides the instructions instantly. I think this is because both mouse click listeners are firing from the same click. Things are set up like this:

1) add an event listener for mouse click on the main menu
2) on click, the instructions image is shown. the old click listener is removed and a new listener is added.
3) the new listener is supposed to dismiss the image and restore the original listener.

When the user clicks, both listeners trigger. Is there an easy way to avoid this?

So far, I just have been using a timer that delays creating the second listener for a couple frames so there is no chance the single click will register twice.

Any tips appreciated…

 
avatar for Vara Vara 746 posts
Flag Post

Use the removeEventListener() function:

removeEventListener(type:String,listener:Function[,useCapture:Boolean=false):void

 
avatar for NeoClassic NeoClassic 8 posts
Flag Post

I have used that. What I mean is that the initial CLICK event triggers a function that installs a new CLICK listener on the next screen.

With a single click, however, both listeners end up firing.

SCREEN1: mouse click listener takes user to screen2
SCREEN2: mouse click listener takes user to screen3

One click is causing the movie to go from SCREEN1 to SCREEN3.

 
avatar for Erasmus_Darwin Erasmus_Darwin 76 posts
Flag Post

Does calling either the stopPropagation() or stopImmediatePropagation() methods on the event work?

 
avatar for colintso colintso 150 posts
Flag Post

What if you used timer detection?

 
avatar for Cervello Cervello 76 posts
Flag Post

I’d suggest using MouseEvent.MOUSE_DOWN and MouseEvent.MOUSE_UP listeners instead of CLICK.

Have one mouseDown boolean and one MOUSE_UP listener, and a MOUSE_DOWN listener in place of each CLICK listener you have. Use a quick if statement to make the MOUSE_DOWN code run only if mouseDown is false, then if mouseDown is false, set mouseDown to true, add the new listener, take the user to the next screen and remove the old listener. In the MOUSE_UP listener set mouseDown false again.

 
avatar for NeoClassic NeoClassic 8 posts
Flag Post

Thanks for the tips—I am going to try the stopPropagation(), but I can see a good case for switching over to the MOUSE_UP/MOUSE_DOWN approach in general.

 
avatar for WW52 WW52 3 posts
Flag Post

you could also probably set the mouse click as a variable, set the first mouse click as an if statement that it watches for, once the if statement is opened, reset the click value to the up position and then repeat to go from the second page to the next page or home screen(dunno how well this will work in as, im used to autoit and c++/am new to as)

Sign in to reply


Click Here