- Flash Development for Android Cookbook
- Joseph Labrecque
- 430字
- 2021-04-02 19:15:20
Verifying specific gesture support for common interactions
When dealing with Android devices, touch and gestures are the main mechanisms with which the user interacts with the device. If we want to use some of the predefined gestures in Flash Player and AIR, we can do so in the following manner.
How to do it...
To discover which specific gestures are supported on a device, perform the following actions:
- First, import the following classes into your project:
import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Stage; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.ui.Multitouch; import flash.ui.MultitouchInputMode;
- Declare a
TextField
andTextFormat
object to allow visible output upon the device:private var traceField:TextField; private var traceFormat:TextFormat;
- We will now set up our
TextField
, apply aTextFormat
, and add it to theDisplayList
. Here, we create a method to perform all of these actions for us:protected function setupTextField():void { traceFormat = new TextFormat(); traceFormat.bold = true; traceFormat.font = "_sans"; traceFormat.size = 44; traceFormat.align = "center"; traceFormat.color = 0x333333; traceField = new TextField(); traceField.defaultTextFormat = traceFormat; traceField.selectable = false; traceField.mouseEnabled = false; traceField.width = stage.stageWidth; traceField.height = stage.stageHeight; addChild(traceField); }
- Set the specific input mode for the multitouch APIs to support gestures with the following command:
Multitouch.inputMode = MultitouchInputMode.GESTURE;
- Invoking
Multitouch.supportedGestures
will return aVector
ofString
objects naming all the supported gestured exposed to Flash on the device:var supportedGestures:Vector.<String> = Multitouch.supportedGestures;
- We can then look for a specific gesture or set of gestures to listen for, or fall back to other interaction events if necessary.
for(var i:int=0; i < supportedGestures.length; ++i) { trace(supportedGestures[i]); }
- We can perform all of these necessary functions within a single method:
protected function checkGestures():void { Multitouch.inputMode = MultitouchInputMode.GESTURE; if(Multitouch.supportedGestures){ var supportedGestures:Vector.<String> = Multitouch.supportedGestures; for(var i:int=0; i <supportedGestures.length; ++i) { traceField.appendText(supportedGestures[i] + "\n"); } }else{ traceField.appendText("no gesture support!"); } }
- The result will appear similar to the following:
How it works...
Flash player and AIR do a marvelous job of distilling information to essential details for an Android developer. Knowing which particular gestures are supported on a device will allow us to tailor event interactions on our applications and provide fallback interactions when necessary.
There's more...
In our example class, we also provide a check to be sure there are at least some gestures supported through Multitouch.supportedGestures
. Chances are, if the device does provide gesture support, we will want to provide a warning to the user explaining that the application will not perform optimally because of hardware limitations.
Apart from the more common gestures such as zoom, swipe, rotate, and pan, which are included in the flash.events.TransformGestureEvent
package, there are additional, yet less common gestures such as two-finger tap, found in the flash.events.GestureEvent
and flash.events.PressAndTapGestureEvent
classes. These will all be referenced by Multitouch.supportedGestures
if available on the device.
- 基于元胞自動機的城市路網交通流建模與仿真
- 中文版Premiere影視編輯課堂實錄
- Cinema 4D 2024+AI工具詳解與實戰(視頻微課·全彩版)
- 數碼攝影后期處理秘笈:Photoshop CC專業調色(第2版)
- AI繪畫:Stable Diffusion從入門到精通
- PHP 5 Social Networking
- Power Query從入門到精通
- SolidWorks 2018快速入門及應用技巧
- 新印象Premiere短視頻拍攝+剪輯+特效關鍵技術
- Origin 2022科學繪圖與數據分析(高級應用篇)
- After Effects 影視后期特效:短視頻制作實戰寶典
- Inkscape Starter (Microcontent)
- 從零開始:Dreamweaver CS6中文版基礎培訓教程
- Premiere視頻編輯案例教程:Premiere Pro 2020(微課版·第2版)
- Oracle ADF Enterprise Application Development—Made Simple