The Accelerometer
class works in tandem with the device's motion sensor to measure and report movement and acceleration coordinates as the device is moved through 3D space. To measure this data and react to these measurements, we must perform certain actions to allow the gathering of accelerometer data within our application.
We will need to employ certain ActionScript classes to allow monitoring of accelerometer feedback:
1. First, import the following classes into your project:
import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.AccelerometerEvent; import flash.sensors.Accelerometer; import flash.text.TextField; import flash.text.TextFormat;
2. Declare a
TextField
andTextFormat
object pair to allow visible output upon the device, along with anAccelerometer
object:private var traceField:TextField; private var traceFormat:TextFormat...