Skip to main content
Inspiring
Oct 13, 2012 1:42 PM UTC
Question

mouseUp unreliable on iOS (see code)

About half the time, I find buttons using the code below get stuck in the "down" state. There is no relible factor - sometimes the MOUSE_UP works and sometimes it doesn't. What am I doing wrong here?? (This is on iOS, BTW)

Any thoughts?

---------------------------------------

package  {

          import flash.display.MovieClip;

          import flash.events.MouseEvent;

          import flash.events.Event;

          public class buttons extends MovieClip {

                    public function buttons()

                   {

                              this.gotoAndStop(1);

                              this.addEventListener(MouseEvent.MOUSE_DOWN, downPress);

                              this.mouseChildren = false;

                    }

                    private function downPress(event:MouseEvent):void

                    {

                //frame 4 in my button mc holds the down btn graphic

                              this.gotoAndStop(4);

                              this.addEventListener(MouseEvent.MOUSE_UP, upChuck);

                              this.addEventListener(MouseEvent.MOUSE_OUT, rollingOut);

                              this.removeEventListener(MouseEvent.MOUSE_DOWN, downPress);

                    }

                    private function rollingOut(event:MouseEvent):void

                    {

                              this.gotoAndStop(1);

                              this.addEventListener(MouseEvent.MOUSE_DOWN, downPress);

                              this.removeEventListener(MouseEvent.MOUSE_OUT, rollingOut);

                              this.removeEventListener(MouseEvent.MOUSE_UP, upChuck);

                    }

                    private function upChuck(event:MouseEvent):void

                    {

                              this.gotoAndStop(1);

                              this.removeEventListener(MouseEvent.MOUSE_UP, upChuck);

                              this.removeEventListener(MouseEvent.MOUSE_OUT, rollingOut);

                              this.addEventListener(MouseEvent.MOUSE_DOWN, downPress);

                              trace("up");

                    }

          }

}

This topic is closed to new replies. Start a new post to keep the conversation going.

12 replies

Participating Frequently
Oct 14, 2012 9:49 AM UTC

I could be wrong, but Im guessing RollOut triggered instead of MouseOut. Since there are discussions about the difference between ROLL_OUT and MOUSE_OUT, maybe listening to MouseEvent.ROLL_OUT can solve your problem.

Maybe you can try replacing MouseEvent.MOUSE_OUT with MouseEvent.ROLL_OUT and see if the problem still reside. Good luck

Translate
gtrAuthor
Inspiring
Oct 14, 2012 3:18 PM UTC

Thanks for the reply Eddy.Li,

It's definitely an issue with the MOUSE_UP and not with the MOUSE_OUT. I did try your suggestion anyway, just to be sure though... : )

UPDATE:

Upon further investigation, I just realized not only is the MOUSE_UP not being called, but the button's mouseEvent.CLICK function is not triggered either.

Translate
Participating Frequently
Oct 14, 2012 6:33 PM UTC

Could there be something on top of your button that had picked up the event? I once had some weird problems where the STAGE picked up all my events. Well, I got to admit that was bad coding.

Nowadays I only have one handler for each events at STAGE. These handlers just call the event handling functions in the objects on STAGE. Then I call hitTestPoint on my buttons. I suppose it's not the friendliest way to do it, but at least I don't have to worry about removing event listeners. It might sound crazy, which it probably is, but I find I have more control of everything.

I don't think somewhere above your button called stopPropagation() or stopImmediatePropagation(). Since it does work sometimes. Which makes it seems even more interesting. And I can't find anything suspicious in your code.

Anyways, no sure what else I can suggest. Since I'm not use to the debugger. Hopefully some wise men on this forum can come up with a solution. Good luck to you

Translate