Skip to main content
Participant
October 14, 2011
Question

Button multitouch events problem

  • October 14, 2011
  • 1 reply
  • 731 views

Hi all,

I'm currently developing an air android mobile platform game.. it uses 3 multitouch buttons (Sprites) (left, right, up) in the corners of the screen to move around. So if you press them the player moves around. The problem is that if you touch it with a quick slide kind of a movement which goes out of the button area range the button stays on and the player is for example like jumping forever... here is the code:

package  {

    import flash.display.Sprite;

    import flash.events.TouchEvent;

    import flash.ui.Multitouch;

    import flash.ui.MultitouchInputMode;

    public class TouchControl extends Sprite

    {

        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

       

        public var button:Sprite;

        public var touch:Boolean;

       

        public function TouchControl(X : Number = 0, Y : Number = 0, R : Number = 0, colour:Number  = 0xFFFFFF)

        {           

            button = new Sprite();

            button.graphics.beginFill(colour);

            button.graphics.drawCircle(X,Y, R);

            button.graphics.endFill();

           

            //listeners

            AddListeners();

            Stage.addChild(button);

        }

       

        public function AddListeners():void

        {

            button.addEventListener(TouchEvent.TOUCH_BEGIN, touched);

            button.addEventListener(TouchEvent.TOUCH_OVER, touched);

            button.addEventListener(TouchEvent.TOUCH_OUT, notouched);

            button.addEventListener(TouchEvent.TOUCH_END, notouched);

        }

       

        public function RemoveListeners():void

        {

            button.removeEventListener(TouchEvent.TOUCH_BEGIN, touched);

            button.removeEventListener(TouchEvent.TOUCH_OVER, touched);

            button.removeEventListener(TouchEvent.TOUCH_OUT, notouched);

            button.removeEventListener(TouchEvent.TOUCH_END, notouched);

        }

       

        private function touched(e:TouchEvent):void

        {

            touch = true;

        }

       

        private function notouched(e:TouchEvent):void

        {

            touch = false;

        }

       

        public function isTouched():Boolean

        {

            return touch;

        }

    }

}

So the question is why TouchEvent.TOUCH_END is not fired correctly all the time and the button acts like touched but it isn't?

This topic has been closed for replies.

1 reply

Inspiring
October 14, 2011

I had the same problem and made a thread a couple of days ago or so. Your answer + more is in the thread.

http://forums.adobe.com/message/3965160#3965160

napolyAuthor
Participant
October 15, 2011

hi TenchyMyo.. & thx for your answer

so my code looks like this now:

package  {

    import flash.display.Sprite;

    import flash.events.TouchEvent;

    import flash.ui.Multitouch;

    import flash.ui.MultitouchInputMode;

    public class TouchControl extends Sprite

    {

        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

       

        public var button:Sprite;

        public var touch:Boolean;

       

        public function TouchControl(X : Number = 0, Y : Number = 0, R : Number = 0, colour:Number  = 0xFFFFFF)

        {           

            button = new Sprite();

            button.graphics.beginFill(colour);

            button.graphics.drawCircle(X,Y, R);

            button.graphics.endFill();

           

            //listeners

            AddListeners();

            Stage.addChild(button);

        }

       

        public function AddListeners():void

        {

            button.addEventListener(TouchEvent.TOUCH_ROLL_OUT, notouched);

            button.addEventListener(TouchEvent.TOUCH_ROLL_OVER, touched);

        }

       

        public function RemoveListeners():void

        {

            button.addEventListener(TouchEvent.TOUCH_ROLL_OUT, notouched);

            button.addEventListener(TouchEvent.TOUCH_ROLL_OVER, touched);

        }

       

        private function touched(e:TouchEvent):void

        {

            touch = true;

        }

       

        private function notouched(e:TouchEvent):void

        {

            touch = false;

        }

       

        public function isTouched():Boolean

        {

            return touch;

        }

    }

}

Well now the buttons roll out fires correctly.. but if you press the button with a finger (and don't move with it) the button is not pressed (you have to move a little with it so the TouchEvent.TOUCH_ROLL_OVER will get dispatched)... in the last comment of your thread you wrote that TOUCH_ROLL_OUT works as TOUCH_BEGIN.. but in my case it doesnt.. or I'm doing something wrong..?!?! could you pls post a code..?

napolyAuthor
Participant
October 15, 2011

Just to mention I also tried them together:

        public function AddListeners():void

        {

            button.addEventListener(TouchEvent.TOUCH_BEGIN, touched);

            button.addEventListener(TouchEvent.TOUCH_ROLL_OVER, touched);

            button.addEventListener(TouchEvent.TOUCH_ROLL_OUT, notouched);

            button.addEventListener(TouchEvent.TOUCH_END, notouched);

        }

       

        public function RemoveListeners():void

        {

            button.removeEventListener(TouchEvent.TOUCH_BEGIN, touched);

            button.removeEventListener(TouchEvent.TOUCH_ROLL_OVER, touched);

            button.removeEventListener(TouchEvent.TOUCH_ROLL_OUT, notouched);

            button.removeEventListener(TouchEvent.TOUCH_END, notouched);

        }

But the old problem came up.. so if you touch the button with a quick slide kind of a movement it stays on.. :[