The TouchEvent Class

A touch event is similar to a mouse event, except that you can have multiple inputs at once. Because this event uses more power, you should only use it if you need to capture more than one point. If you only need to track one point, the mouse event will work well even though your mouse is now a finger.

Touches are also called raw touch data because you receive them as is. If you want to interpret them as gestures, you need to write the logic yourself or use a third-party library.

First, set the input mode to TOUCH_POINT:

import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.TouchEvent;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

TOUCH_TAP is similar to a mouse up event. The following code creates a simple application where every touch creates a new circle:

import flash.events.TouchEvent;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

stage.addEventListener(TouchEvent.TOUCH_TAP, onTouchTap);

function onTouchTap(event:TouchEvent):void {
    var sprite:Sprite = new Sprite();
    sprite.graphics.lineStyle(25, Math.random()*0xFFFFFF);
    sprite.graphics.drawCircle(0, 0, 80);
    sprite.x = event.stageX;
    sprite.y = event.stageY;
    addChild(sprite);
}

The touchPointID is a new and important event property. Each new touch has a unique ID associated with it, from TOUCH_BEGIN to TOUCH_END. touchPointID gives you a way to identify and store every point and associate data with it if needed.

In this example, we use an Object to store the ID as ...

Get Developing Android Applications with Adobe AIR now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.