Demonstration of Gesture APIs in AIR 2

I don’t have a multi-touch computer (yet), but I do have a MacBook with a multi-touch trackpad which means I can write AIR 2 applications that incorporate gestures. The video below demonstrates a few of the new gesture APIs in AIR 2:

The code below shows how to indicate that you want to receive gesture events (as opposed to multi-touch, or no touch events at all), and registers for zoom, rotate, and pan gesture events (the watch variable refers to a Sprite which contains the bitmap image of the watch):

Multitouch.inputMode = MultitouchInputMode.GESTURE;
watch.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
watch.addEventListener(TransformGestureEvent.GESTURE_ROTATE, onRotate);
watch.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);

The three functions below show responding to each of the gesture events:

private function onZoom(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
watch.scaleX *= e.scaleX;
watch.scaleY *= e.scaleY;
}

private function onRotate(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
watch.rotation += e.rotation;
}

private function onPan(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
var watchBitmap:Bitmap = watch.getChildAt(0) as Bitmap;
watchBitmap.x += e.offsetX;
watchBitmap.y += e.offsetY;
}

For much more information on how multi-touch and gestures work in both AIR 2 and Flash Player 10.1 (including OS and hardware support, which gestures are supported where, and a thorough review of the APIs), and to download sample code, see Multi-touch and Gesture Support on the Flash Platform. Or, if you just want to see the code for this sample, you can download it here.