Package | flash.ui |
Class | public final class Multitouch |
Inheritance | Multitouch Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 10.1, AIR 2, Flash Lite 4 |
- 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.
More examples
Learn more
Christian Cantrell: Multitouch and gesture support on the Flash Platform
Lee Brimelow: Flash Player 10.1 multi-touch FAQ
Piotr Walczyszyn: Multitouch development in Flex
Related API Elements
flash.events.GestureEvent
flash.events.TransformGestureEvent
flash.events.GesturePhase
flash.events.PressAndTapGestureEvent
flash.events.MouseEvent
flash.events.EventDispatcher.addEventListener()
Property | Defined By | ||
---|---|---|---|
constructor : 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 | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | ||
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 |
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 )
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 |
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
flash.events.MouseEvent
flash.events.EventDispatcher.addEventListener()
flash.events.GestureEvent
flash.events.PressAndTapGestureEvent
flash.events.TransformGestureEvent
Example ( How to use this example )
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
Example ( How to use this example )
var myTextField:TextField = new TextField(); myTextField.width = 200; addEventListener(Event.ENTER_FRAME, enterhandler); function enterhandler(e:Event): void { var support:Boolean = Multitouch.supportsTouchEvents; switch (support) { case true : myTextField.text = "Touch events supported"; break; case false : myTextField.text = "Touch events not supported"; break; default : myTextField.text = "unknown"; } addChild(myTextField); }
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); } } } } }
Mon Nov 28 2011, 06:48 AM -08:00