Skip to main content
Inspiring
July 31, 2013
Answered

Multitouch multiple touch points confusion

  • July 31, 2013
  • 1 reply
  • 2195 views

I am trying to implement multiple touch points for the first time.  I'm testing on a Samsung Galaxy Tab 2 7.0; if I do device debugging over USB, AIR reports that the device supports 2 touch points and touch events are supported.

The app I'm working on is in the early stages, so there's not much going on at the moment. I have two SimpleButtons that I'm trying to set up so the user can press both of them at the same time, but I can't get it to work right. If I hold the first button and then press the second button, the first button stays pressed and the second button doesn't recognize a press (the SimpleButton doesn't even change its background to the pressed state). If I hold the second button and then press the first button, the first button does nothing, and the second button is released (both in my code and visually).

public function enableButtons():void {

     Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

     trace("supportsTouchEvents:" + Multitouch.supportsTouchEvents);

     button1.addEventListener(TouchEvent.TOUCH_BEGIN, onHoldButton, false, 0, true);

     button2.addEventListener(TouchEvent.TOUCH_BEGIN, onHoldButton, false, 0, true);

}

private function onHoldButton(event:TouchEvent):void {

     trace("HOLD BUTTON " + event.target.name);

     var button:SimpleButton = event.currentTarget as SimpleButton;

     button.removeEventListener(TouchEvent.TOUCH_BEGIN, onHoldButton);

     button.addEventListener(TouchEvent.TOUCH_END, onReleaseButton, false, 0, true);

     button.addEventListener(TouchEvent.TOUCH_OUT, onReleaseButton, false, 0, true);

}

private function onReleaseButton(event:TouchEvent):void {

     trace("RELEASE BUTTON"  + event.target.name);

     var button:SimpleButton = event.currentTarget as SimpleButton;

     button.addEventListener(TouchEvent.TOUCH_BEGIN, onHoldButton, false, 0, true);

     button.removeEventListener(TouchEvent.TOUCH_END, onReleaseButton);

     button.removeEventListener(TouchEvent.TOUCH_OUT, onReleaseButton);

}

Am I doing something wrong here? Do SimpleButtons not support multitouch?

This topic has been closed for replies.
Correct answer Mark.fromOP

"With mouse events you never have to worry about multiple clicks at once since you only have the one mouse. "

I know, I'm just saying the code

    var button:SimpleButton = event.currentTarget as SimpleButton;

     button.removeEventListener(TouchEvent.TOUCH_BEGIN, onHoldButton);

will not prevent the events from working correctly, as the TOUCH_BEGIN event is only removed from the button that is already touched, not affecting the button that wasn't touched yet.

Here's the answer: SimpleButton does NOT support Multitouch. I changed the buttons to a custom class and the problem went away. I usually do code my own components rather than using Adobe's components, and I've even done my own two-state buttons in the past, but for this project I had assumed SimpleButton would be adequate. Apparently not!

Thank you for your assistance, I probably would have wasted more hours before trying a different button class if you hadn't said SimpleButton works poorly with touch events. Would you like to add the note that SimpleButton does not support Multitouch to your post so anyone else who has this problem will see the answer more easily?

Should a bug report be filed about SimpleButton not supporting Multitouch?


Cant seem to edit my post, so here is the short of it based on your discoveries.

Here's the answer: SimpleButton does NOT support Multitouch.

You can mark this or your own reply as correct.

1 reply

Colin Holgate
Inspiring
August 1, 2013

You’re using TOUCH_OUT. Might the press on the second button be seen as a touch out for the first button. What happens if you don’t use that listener?

Mark.fromOP
Inspiring
August 1, 2013

Yeah what Colin said, insted of TOUCH_OUT use TOUCH_ROLL_OUT maybe?

xTLSAuthor
Inspiring
August 1, 2013

Thanks for the suggestion; I tried taking out the TOUCH_OUT event, but that doesn't make multitouch work, it merely prevents pressing the second button from releasing the first button.

Normally the SimpleButton changes to the DOWN state when you press it; you don't have to code anything to do this, merely provide images for the different states. Since only one SimpleButton will visually change state at a time, it seems like AIR isn't registering more than one touch point to begin with, rather than that there's a problem with my touch functions. The MultitouchInputMode doesn't get changed anywhere else so I really have no idea what's wrong unless there's something else I need to do to enable it that I'm not aware of