When developing projects which target the Android operating system, it is always a good idea to make sure that certain sensors, such as the accelerometer, are actually supported on the device. In the case of an Android phone, this will probably always be the case, but we should never assume the capabilities of any device.
We will need to use Accelerometer API classes to detect whether or not an accelerometer is supported:
1. 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.sensors.Accelerometer;
2. Declare a
TextField
andTextFormat
object pair to allow visible output upon the device:private var traceField:TextField; private var traceFormat:TextFormat;
3. We will now set up our
TextField
, apply aTextFormat...