13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Touch, multitouch and gesture input<br />

Touch support discovery<br />

Flash Player 10.1 and later, Adobe AIR 2 and later<br />

Use the Multitouch class properties to set the scope of touch input your application handles. Th<strong>en</strong>, test the<br />

<strong>en</strong>vironm<strong>en</strong>t to <strong>en</strong>sure that support exists for the ev<strong>en</strong>ts your ActionScript handles. Specifically, first establish the type<br />

of touch input for your application. The options are: touch point, gesture, or none (interpret all touch input as mouse<br />

clicks and use mouse ev<strong>en</strong>t handlers, only). Th<strong>en</strong>, use the properties and methods of the Multitouch class to make sure<br />

that the runtime is in an <strong>en</strong>vironm<strong>en</strong>t that supports the touch input your application requires. Test the runtime<br />

<strong>en</strong>vironm<strong>en</strong>t for support of the types of touch input (such as whether it can interpret gestures), and respond<br />

accordingly.<br />

Note: The Multitouch class properties are static properties, and do not belong to instances of any class. Use them with the<br />

syntax Multitouch.property, for example:<br />

var touchSupport:Boolean = Multitouch.supportsTouchEv<strong>en</strong>ts;<br />

Set the input type<br />

The Flash runtime must know the type of touch input to interpret, because a touch ev<strong>en</strong>t can have many elem<strong>en</strong>ts or<br />

phases. If a finger simply touches a touch-<strong>en</strong>abled scre<strong>en</strong>, does the runtime dispatch a touch ev<strong>en</strong>t? Or does it wait for<br />

a gesture? Or does the runtime track the touch as a mouse-down ev<strong>en</strong>t? An application that supports touch input must<br />

establish the type of touch ev<strong>en</strong>ts it handles for the Flash runtime. Use the Multitouch.inputMode property to<br />

establish the type of touch input for the runtime. The input mode can be one of three options:<br />

None No special handling is provided for touch ev<strong>en</strong>ts. Set: Multitouch.inputMode=MultitouchInputMode.NONE<br />

and use the MouseEv<strong>en</strong>t class to handle input.<br />

Single touch points All touch input is interpreted, individually, and all touch points can be tracked and handled. Set:<br />

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT and use the TouchEv<strong>en</strong>t class to handle input.<br />

Gesture input The device or operating system interprets input as a complex form of finger movem<strong>en</strong>t across the<br />

scre<strong>en</strong>. The device or operating system collectively assigns the movem<strong>en</strong>t to a single gesture input ev<strong>en</strong>t. Set:<br />

Multitouch.inputMode=MultitouchInputMode.GESTURE and use the TransformGestureEv<strong>en</strong>t,<br />

PressAndTapGestureEv<strong>en</strong>t, or GestureEv<strong>en</strong>t classes to handle input.<br />

See “Touch ev<strong>en</strong>t handling” on page 584 for an example that uses the Multitouch.inputMode property to set the<br />

input type before handling a touch ev<strong>en</strong>t.<br />

Test for touch input support<br />

Other properties of the Multitouch class provide values for fine-tuning your application to the curr<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t’s<br />

touch support. The Flash runtime populates values for the number of simultaneous touch points allowed or gestures<br />

available. If the runtime is in an <strong>en</strong>vironm<strong>en</strong>t that does not support the touch ev<strong>en</strong>t handling your application needs,<br />

provide the user with an alternative. For example, provide mouse ev<strong>en</strong>t handling or information about what features<br />

are available, or not, in the curr<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

You can also use the API for keyboard, touch, and mouse support, see “Discovering input types” on page 557.<br />

For more information about compatibility testing, see “Troubleshooting” on page 592.<br />

Last updated 6/6/2012<br />

583

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!