Not yet rated
Tags:



Problem

Recipe to test the Multi-touch functionality using AIR 2.0 and Flash Player 10.1

Solution

We first switch between the different options and than we listen to the gesture events which will fire and display the gesture information in the console.

Detailed explanation



 Multi-touch is one of the most exciting features in AIR 2.  The API is matching the Flash Player 10.1, which will use by mobile devices.  Although most of our devices don't support Multi-touch user gestures, the excitement is more about the possibilities since it's clear to many that using touch screen is becoming very popular.  There is a new event called TouchEvent, which gets dispatch when the Flash player detects a user gesture.


MultitouchInputMode  is the enumeration class that holds the three types of multi-touch hardware options.
Flash player identify weather the device is capable touch events with multiple points of contact and specific events for different gestures (such as rotation and pan), or only a single point of contact (such as tap), or none at all (contact is handled as a mouse event).

 

  • GESTURE = "gesture" - multiple points of contact and specific events for different gestures (such as rotation and pan)
  • NONE = "none" -  none at all.
  • TOUCH_POINT = "touchPoint" -  basic single point of contact (such as tap)
     

First you need to set the Multitouch class to the type of user gesture that the device is capable of capturing. Than you can start listening to gesture events.
Take a look at the example below.  We first switch between the different options and than we listen to the gesture events which will fire and display the gesture information in the console.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                      
creationComplete="creationCompleteHandler()">
    <fx:Script>
        <![CDATA[
            import flash.events.TransformGestureEvent;
            import flash.system.Capabilities;
            import flash.system.TouchscreenType;
            import flash.ui.Multitouch;
            import flash.ui.MultitouchInputMode;
           
            protected function creationCompleteHandler():void
            {
                if ( Capabilities.touchscreenType ==
TouchscreenType.NONE )
                {
                    trace("Multitouch is not supported on this
device");
                    Multitouch.inputMode =
MultitouchInputMode.NONE;
                    return;
                }
               
                if( Capabilities.touchscreenType ==
TouchscreenType.FINGER )
                {
                    Multitouch.inputMode =
MultitouchInputMode.TOUCH_POINT;
                }
                else if ( Capabilities.touchscreenType ==
TouchscreenType.STYLUS )
                {
                    Multitouch.inputMode =
MultitouchInputMode.GESTURE;
                }
               
                // Transform Listeners
               
this.addEventListener(TransformGestureEvent.GESTURE_ZOOM,
eventHandler);
               
this.addEventListener(TransformGestureEvent.GESTURE_SWIPE,
eventHandler);
               
this.addEventListener(TransformGestureEvent.GESTURE_PAN,
eventHandler);
               
this.addEventListener(TransformGestureEvent.GESTURE_ROTATE,
eventHandler);
               
                // Touch Listeners
                this.addEventListener(TouchEvent.TOUCH_BEGIN,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_END,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_MOVE,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_OUT,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_OVER,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_ROLL_OUT,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_ROLL_OVER,
eventHandler);
                this.addEventListener(TouchEvent.TOUCH_TAP,
eventHandler);               
            }
           
            protected function eventHandler(event:TouchEvent) :
void
            {
                trace( event.toString() );
            }

        ]]>
    </fx:Script>

</s:WindowedApplication>

To learn more about this feature and more order AdvancED Flex 4


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes