To handle multitouch in AIR you need to listen to TouchEvent events like TouchEvent.TOUCH_BEGIN
. Which event you will listen depends on the Multitouch.inputMode
defined, possile values are enumerated in MultitouchInputMode class. We will use MultitouchInputMode.TOUCH_POINT
which specifies that events are dispatched only for basic touch events, such as a single finger tap.
It would be also good to make sure that we have touch enabled device or if we have enough number of touch points recognised, this information can be fetched from Multitouch class.
var m_oTouchIDs:Object;
if(Multitouch.supportsTouchEvents)
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
m_oTouchIDs = { };
//we have touch screen
stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
}
protected function onTouchMove(e:TouchEvent):void
{
//update
var p:Point = m_oTouchIDs[e.touchPointID] as Point;
p.x = e.localX;
p.y = e.localY;
}
protected function onTouchEnd(e:TouchEvent):void
{
delete m_oTouchIDs[e.touchPointID];//release
}
protected function onTouchBegin(e:TouchEvent):void
{
m_oTouchIDs[e.touchPointID] = new Point(e.localX, e.localY);
}
Than you have an object containing position (and it could contain other details if needed) of each touch point which could be later used e.g. in a loop to verify what was “clicked”.
best regards