ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
flash.ui 

Multitouch  - AS3

Packageflash.ui
Classpublic final class Multitouch
InheritanceMultitouch Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

The Multitouch class manages and provides information about the current environment's support for handling contact from user input devices, including contact that has two or more touch points (such as a user's fingers on a touch screen). When a user interacts with a device such as a mobile phone or tablet with a touch screen, the user typically touches the screen with his or her fingers or a pointing device. While there is a broad range of pointing devices, such as a mouse or a stylus, many of these devices only have a single point of contact with an application. For pointing devices with a single point of contact, user interaction events can be handled as a mouse event, or using a basic set of touch events (called "touch point" events). However, for pointing devices that have several points of contact and perform complex movement, such as the human hand, Flash runtimes support an additional set of event handling API called gesture events. The API for handling user interaction with these gesture events includes the following classes:

  • flash.events.TouchEvent
  • flash.events.GestureEvent
  • flash.events.GesturePhase
  • flash.events.TransformGestureEvent
  • flash.events.PressAndTapGestureEvent

Use the listed classes to write code that handles touch events. Use the Multitouch class to determine the current environment's support for touch interaction, and to manage the support of touch interaction if the current environment supports touch input.

You cannot create a Multitouch object directly from ActionScript code. If you call new Multitouch(), an exception is thrown.

Note: The Multitouch feature is not supported for SWF files embedded in HTML running on Mac OS.

View the examples

More examples

Learn more

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  inputMode : String
[static] Identifies the multi-touch mode for touch and gesture event handling.
Multitouch
      mapTouchToMouse : Boolean
[static] Specifies whether the AIR runtime maps touch events to mouse events.
Multitouch
  maxTouchPoints : int
[static] [read-only] The maximum number of concurrent touch points supported by the current environment.
Multitouch
  supportedGestures : Vector.<String>
[static] [read-only] A Vector array (a typed array of string values) of multi-touch contact types supported in the current environment.
Multitouch
  supportsGestureEvents : Boolean
[static] [read-only] Indicates whether the current environment supports gesture input, such as rotating two fingers around a touch screen.
Multitouch
  supportsTouchEvents : Boolean
[static] [read-only] Indicates whether the current environment supports basic touch input, such as a single finger tap.
Multitouch
Public Methods
 MethodDefined By
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail

inputMode

property
inputMode:String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

Identifies the multi-touch mode for touch and gesture event handling. Use this property to manage whether or not events are dispatched as 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). To set this property, use values from the flash.ui.MultitouchInputMode class.

The default value is gesture.



Implementation
    public static function get inputMode():String
    public static function set inputMode(value:String):void

Related API Elements


Example  ( How to use this example )
The following example displays a message when the square drawn on mySprite is tapped on a touch-enabled screen:
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

var mySprite:Sprite = new Sprite();
var myTextField:TextField = new TextField();

mySprite.graphics.beginFill(0x336699);
mySprite.graphics.drawRect(0,0,40,40);
addChild(mySprite);

mySprite.addEventListener(TouchEvent.TOUCH_TAP, taphandler);

function taphandler(e:TouchEvent): void {
    myTextField.text = "I've been tapped";
    myTextField.y = 50;
    addChild(myTextField);
}
    

mapTouchToMouse

property 
mapTouchToMouse:Boolean

Language Version: ActionScript 3.0
Runtime Versions: AIR 3

Specifies whether the AIR runtime maps touch events to mouse events.

When true, the default, the AIR runtime dispatches a mouse event in addition to a touch event for touch inputs. When false, the runtime does not dispatch an additional mouse event. Setting this property to false can cause existing code, libraries, and frameworks that rely on mouse events to function incorrectly on devices that support touch input.



Implementation
    public static function get mapTouchToMouse():Boolean
    public static function set mapTouchToMouse(value:Boolean):void

Related API Elements

maxTouchPoints

property 
maxTouchPoints:int  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

The maximum number of concurrent touch points supported by the current environment.



Implementation
    public static function get maxTouchPoints():int

Related API Elements

supportedGestures

property 
supportedGestures:Vector.<String>  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

A Vector array (a typed array of string values) of multi-touch contact types supported in the current environment. The array of strings can be used as event types to register event listeners. Possible values are constants from the GestureEvent, PressAndTapGestureEvent, and TransformGestureEvent classes (such as GESTURE_PAN).

If the Flash runtime is in an environment that does not support any multi-touch gestures, the value is null.

Note: For Mac OS 10.5.3 and later, Multitouch.supportedGestures returns non-null values (possibly indicating incorrectly that gesture events are supported) even if the current hardware does not support gesture input.

Use this property to test for multi-touch gesture support. Then, use event handlers for the available multi-touch gestures. For those gestures that are not supported in the current evironment, you'll need to create alternative event handling.



Implementation
    public static function get supportedGestures():Vector.<String>

More examples

Related API Elements


Example  ( How to use this example )
The following example adds the appropriate event listeners for each individual supported gesture in the current environment. The Multitouch.supportedGestures vector array contents change to include all the gestures available to the current software and hardware environment for the Flash runtime. If the Multitouch.supportedGestures vector array does not contain one of the TransformGestureEvent gestures, then no event listener is added for that gesture. This example comes from Holly Schinsky.
Multitouch.inputMode = MultitouchInputMode.GESTURE;

    for each (var item:String in Multitouch.supportedGestures) {
        trace("gesture " + item);
        if (item == TransformGestureEvent.GESTURE_PAN)
            img.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);
        else if (item == TransformGestureEvent.GESTURE_ROTATE)
            img.addEventListener(TransformGestureEvent.GESTURE_ROTATE, onRotate);
        else if (item == TransformGestureEvent.GESTURE_SWIPE)
            img.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
        else if (item == TransformGestureEvent.GESTURE_ZOOM)
            img.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
    }

supportsGestureEvents

property 
supportsGestureEvents:Boolean  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

Indicates whether the current environment supports gesture input, such as rotating two fingers around a touch screen. Gesture events are listed in the TransformGestureEvent, PressAndTapGestureEvent, and GestureEvent classes.

Note: For Mac OS 10.5.3 and later, this value is always true. Multitouch.supportsGestureEvent returns true even if the hardware does not support gesture events.



Implementation
    public static function get supportsGestureEvents():Boolean

More examples

Related API Elements

supportsTouchEvents

property 
supportsTouchEvents:Boolean  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10.1, AIR 2, Flash Lite 4

Indicates whether the current environment supports basic touch input, such as a single finger tap. Touch events are listed in the TouchEvent class.



Implementation
    public static function get supportsTouchEvents():Boolean

More examples

Related API Elements

MultitouchExample.as

The following example first checks to see if gesture events are supported (if the machine doesn't support gesture events, the vector array Multitouch.supportedGestures returns null and assigning null to the vector of strings causes a run-time error). If gesture events are supported, the example displays the events from the TransformGestureEvent class supported in the current environment:
package {
    import flash.ui.Multitouch;
    import flash.ui.MultitouchInputMode;
    import flash.display.Sprite;
    import flash.text.TextField;

    public class MultitouchExample extends Sprite {

        Multitouch.inputMode = MultitouchInputMode.GESTURE;

        public function MultitouchExample() {

            if(Multitouch.supportsGestureEvents){
                var supportedGesturesVar:Vector.<String> = Multitouch.supportedGestures;
                var deviceSupports:TextField = new TextField();
                deviceSupports.width = 200;
                deviceSupports.height = 200;
                deviceSupports.wordWrap = true;

                for (var i:int=0; i<supportedGesturesVar.length; ++i) {
                    deviceSupports.appendText(supportedGesturesVar[i] + ",  ");
                    addChild(deviceSupports);
                }
            }
        }
    }
}