0

I've been fighting with an issue regarding multitouch in as3. I'm trying to make an app where the user should be able to move a picture around the stage (touch_point) as well as zoom on it by gesturing (pinch gesture). Is it even possible?

Thanks!!

dalvallana
  • 469
  • 6
  • 13

3 Answers3

1

These functions will handle the pinch, zoom and dragging.

import flash.events.GestureEvent;
import flash.events.TransformGestureEvent;
import flash.events.GesturePhase;
import flash.events.Event;
import flash.events.MouseEvent;

function fl_ZoomHandler (e:TransformGestureEvent):void {
e.target.scaleX *=  e.scaleX;
e.target.scaleY *=  e.scaleY;

if (e.phase==GesturePhase.END) {
        e.currentTarget.stopDrag();
    }

}


function fl_StartDrag (e:MouseEvent):void {
e.currentTarget.startDrag (false);
theDragItem = e.currentTarget;
}


function fl_StopDrag (e:MouseEvent):void {  
e.currentTarget.stopDrag();
}


function fl_RotateHandler (e:TransformGestureEvent):void {
e.target.rotation +=  e.rotation;

if (e.phase==GesturePhase.END) {
        e.currentTarget.stopDrag();
    }
}

And these are the event listeners to apply to the item you want to affect.

YOUROBJECT.addEventListener(MouseEvent.MOUSE_DOWN, fl_StartDrag, false, 0, true);
YOUROBJECT.addEventListener(MouseEvent.MOUSE_UP, fl_StopDrag, false, 0, true);
YOUROBJECT.addEventListener(TransformGestureEvent.GESTURE_ZOOM, fl_ZoomHandler, false, 0, true);
YOUROBJECT.addEventListener(TransformGestureEvent.GESTURE_ROTATE, fl_RotateHandler, false, 0, true);
crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • Thanks for your answer!! But it doesn't seem to work. I need to switch the MultitouchInputMode from TOUCH_INPUT to GESTURE, and viceversa. Well, I could do this if there would be a way to know when the user ends a gesture by lifting its fingers off the screen... Sadly, GesturePhase.END doesn't tell me that specific moment =(. – dalvallana May 07 '12 at 15:10
  • Is there a specific reason why you need TOUCH_INPUT mode? – crooksy88 May 07 '12 at 15:59
  • Yes... Several reasons, actually. I'm using the TOUCH_BEGIN, TOUCH_MOVE and TOUCH_END event handlers. I'm developing a collaborative drawing application, in which 3 or more children are able to draw simultaneously different shapes, as well as resize by gestures these shapes. This would be a multitouch tabletop application. This is for a prototype I need to develop for my phd thesis. – dalvallana May 08 '12 at 08:10
  • Not sure what the answer is to your specific situation I'm afraid. – crooksy88 May 08 '12 at 11:12
1

MAYBE this could be usefull

http://help.adobe.com/en_US/as3/dev/WS1ca064e08d7aa93023c59dfc1257b16a3d6-7ffd.html

Handle gesture events in the same way as basic touch events. You can listen for a series of gesture events defined by the event type constants in the TransformGestureEvent class, the GestureEvent class and the PressAndTapGestureEvent class.

there's also a new question that arises.. press-and-tap? swipe? http://i.msdn.microsoft.com/dynimg/IC504532.png graphical explanation of each

this site is awesome

Viva StackOverflow!

0

Don't bother using both, you can easily do some adjustments with TouchEvent properties to make gesture events.