- Flash Development for Android Cookbook
- Joseph Labrecque
- 394字
- 2021-04-02 19:15:19
Detecting whether or not a device supports multitouch
When developing projects which target the Android operating system, it is always a good idea to make sure that multitouch is actually supported on the device. In the case of an Android phone, this will probably always be the case, but what about a Google TV or AIR for TV device? Many of these are also Android-based yet most televisions do not have any touch control whatsoever. Never assume the capabilities of any device.
How to do it...
We will need to use internal classes to detect whether or not multitouch is supported:
- 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;
- 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); }
- Then, simply invoke
Multitouch.supportsGestureEvents
andMultitouch.supportsTouchEvents
to check each of these capabilities as demonstrated in the following method:protected function checkMultitouch():void { traceField.appendText(String("Gestures: " + Multitouch.supportsGestureEvents) + "\n"); traceField.appendText(String("Touch: " + Multitouch.supportsTouchEvents)); }
- Each of these properties will return a
Boolean
value oftrue
orfalse
, indicating device support as shown here:
How it works...
Detecting whether the device supports either touch or gesture events will determine how much freedom you, as a developer, have in refining the user experience. If either of these items returns as false, then it is up to you to provide (if possible) an alternative way for the user to interact with the application. This is normally done through Mouse
events:
- Moodle 2.0 E/Learning Course Development
- 中文版3ds Max 2012實用教程(第2版)
- Photoshop CS6 商業應用案例實戰
- Photoshop數碼攝影后期處理專業技法(第2版)
- Spring Web Flow 2 Web Development
- SketchUp印象 城市規劃項目實踐(第2版)
- Talend Open Studio Cookbook
- SPSS進階分析與實務
- Apache Roller 4.0 – Beginner's Guide
- After Effects 2022從新手到高手
- IBM Lotus Notes and Domino 8.5.1
- 魔法詞典:AI繪畫關鍵詞圖鑒(Midjourney版)
- Oracle E/Business Suite R12 Supply Chain Management
- SilverStripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide
- 中文版SolidWorks 2016完全實戰技術手冊