• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Multitouch multiple touch points confusion

Contributor ,
Jul 31, 2013 Jul 31, 2013

Copy link to clipboard

Copied

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?

TOPICS
Development

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 02, 2013 Aug 02, 2013

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.

Votes

Translate

Translate
LEGEND ,
Jul 31, 2013 Jul 31, 2013

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 31, 2013 Jul 31, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2013 Aug 01, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 01, 2013 Aug 01, 2013

Copy link to clipboard

Copied

I believe it has something to do with the fact you remove the listeners in your onHold function.

How about this

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

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

public function enableButtons():void {

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

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

     button1.addEventListener(TouchEvent.TOUCH_ROLL_OUT, onReleaseButton, false, 0, true);

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

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

     button2.addEventListener(TouchEvent.TOUCH_ROLL_OUT, onReleaseButton, false, 0, true);

}

private function onHoldButton(event:TouchEvent):void {

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

     var button:SimpleButton = event.currentTarget as SimpleButton;

     //visual incidator

     button.alpha = 0.5;

}

private function onReleaseButton(event:TouchEvent):void {

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

     var button:SimpleButton = event.currentTarget as SimpleButton;

     //visual incidator

     button.alpha = 1;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2013 Aug 01, 2013

Copy link to clipboard

Copied

That's standard practice though, isn't it? I do that for all of my mouse events to minimize the number of events running at once. Unless the touch events work completely differently and are completely broken, my code is only removing the event from the button that was just pressed (event.target won't affect the other button)

Ignore my code completely. I have two simple buttons, and Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT. A SimpleButton should visually change when you press it, this is built into the SimpleButton. However, only one button is changing color at a time, even when I press both of them. Does this mean Multitouch isn't running at all?

The same problem is occuring on a Transformer Infinity so it must not be a flaw with the Galaxy Tab. The Zoom gesture works fine, for what that's worth. I'm using AIR 3.7, I'll try a different version of AIR tomorrow.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 01, 2013 Aug 01, 2013

Copy link to clipboard

Copied

With mouse events you never have to worry about multiple clicks at once since you only have the one mouse. I can assure you can press more than one button at a time up to 11 on an iPad I believe. I have multi touch apps that allow the user to click something while already engaged in something. I honestly never use SimpleButtons, the button class works poorly with touch events. I recall my first app I had a flash button vs a code it yourself button and it killed performance by now that has probably been fixed but I have long ditched button symbols in favor of my own AS + MC versions.

I would recommend working step by step before simplifying, first proof of concept, two buttons two listeners and even two separate functions, once you get that to work correctly start combining, have them share a function, then have them share a listener but always start from a working solution.

Beware some android devices only support two touch points, keep all fingers clear of the screen when testing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 02, 2013 Aug 02, 2013

Copy link to clipboard

Copied

"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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 02, 2013 Aug 02, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines