Search code examples
actionscript-3gesturetouch-eventpan

ActionScript 3.0 TransformGestureEvent and MouseEvent


I'm trying to use GESTURE_PAN to move a MC and also use MOUSE_CLICK to go to another frame. Many people are saying GESTURE_PAN and MOUSE_CLICK work together BUT THEY WON'T ON MY iPhone. I've read many Q&A on the web and of course on stackoverflow.

stop();

Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);
table.addEventListener(MouseEvent.CLICK, gotoBox);

function onPan(event: TransformGestureEvent): void
{
    table.x += event.offsetX;
    table.y += event.offsetY;
    if (table.x > (table.width / 2))
    {
        table.x = table.width / 2;
    }
    if (table.x < stage.stageWidth - (table.width / 2))
    {
        table.x = stage.stageWidth - (table.width / 2)
    }
    if (table.y > (table.height / 2))
    {
        table.y = table.height / 2;
    }
    if (table.y < stage.stageHeight - (table.height / 2))
    {
        table.y = stage.stageHeight - (table.height / 2)
    }
}
function gotoBox(e: MouseEvent)
{
    trace("mouse")
}

The thing is when i test it on Flash Pro CC Simulator everything works good but not on my iDevice.

Help, I'm running out of time!


Solution

  • There is a special settings mapTouchToMouse flag to change MouseEvent dispatching behavior on device, by default it's set to true so you have mouse events in addition to touch events.

    But that's mostly done for backward compatibility with desktop/browser apps and has certain performance overhead on mobile devices, so bast practice is to set that flag to false and use some mouse/touch events abstraction like Starling touch system or Gestouch

    So check if you changed that mapping to false somewhere, that's the most probable reason why you don't have mouse events.