Skip to main content
eirkerikerik
Participating Frequently
April 8, 2019
Question

Enable several buttons to be pressed at once in Adobe air-app?

  • April 8, 2019
  • 1 reply
  • 761 views

I'm working on a piano-project and would like the player to be able to press several keys (buttons) at the same time. Problem is I can only make one button work at a time (when you try to press more than one, nothing happens). Tried to google the problem but can't find it for my life. Is there a fix to this? Would be amazing!

This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
April 8, 2019

Hi.

You need to change the input mode to allow multitouch/gestures.

Multitouch.inputMode = MultitouchInputMode.GESTURE;

Then, when testing inside of Animate CC, you have to go to the Simulator > TOUCH AND GESTURE > Touch layer and choose the appropriate kind of gesture you want.

Or just test in an actual device.

Regards,

JC

eirkerikerik
Participating Frequently
April 8, 2019

Thank you for a really fast reply! I It didn't work though when I tried the app on my smart pad. I'm a noob when it comes to coding. Do I have to define the gesture (tap in this case)? So far I just used the button functions without any coding involved.

JoãoCésar17023019
Community Expert
Community Expert
April 8, 2019

Here is an example that hopefully will clarify things for you.

I tested this code on an Android Phone and it worked. There may be some touch devices that don't have a good compatibility or no compabitibility with multi touch and/or AIR at all.

AS3 code:

import flash.ui.Multitouch;

import flash.events.TouchEvent;

import flash.ui.MultitouchInputMode;

import flash.display.MovieClip;

var targets:Vector.<MovieClip> = new Vector.<MovieClip>();

function start():void

{

    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

    keys.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);

    stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler);

}

function touchBeginHandler(e:TouchEvent)

{

    targets.unshift(e.target as MovieClip);

    targets[0].gotoAndStop(2);

}

function touchEndHandler(e:TouchEvent)

{

    for (var i:int = targets.length - 1; i >= 0; i--)

          targets.gotoAndStop(1);

    targets.splice(0, targets.length);

}

start();

FLA download:

animate_cc_as3_multitouch.zip - Google Drive

Please don't hesitate to ask if you still have any further questions.

Regards,

JC