The accelerometer sensor can be used when creating all sorts of games or applications for an Android device. One of the more frequent uses of this data is to update the position of a DisplayObject
on the Stage
in response to accelerometer update event data.
We will need to employ certain ActionScript classes to allow monitoring of accelerometer feedback through a DisplayObject
instance. In this example, we will employ a simple Shape
object and change its position based upon this data:
1. First, import the following classes into your project:
import flash.display.Shape; 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. We'll now declare a number of objects to use in the example. First, a
TextField
andTextFormat...