The Accelerometer Class

Must Read

Affiliate Internet Marketing – instructions on how to make money online fast

The term affiliate internet marketing means that you can make money online by using very simple marketing techniques that...

The Tailspin Scenario

This chapter introduces a fictitious company named Tailspin. Tailspin’s flagship product is an online service named Surveys that enables...

Personal Debt Loan Consolidation

I do no believe we ever really have enough money at least I know that I don't because if...

The flash.sensors.Accelerometer class is an addition to ActionScript to support receiving messages from the device’s motion sensor. It is a subclass of the EventDis patcher class. The class is a new Event class that returns the sensor’s updated information.

Measuring acceleration along the perpendicular axes on an Android device

When using these classes, you should first check at runtime that the user’s device has a motion sensor and that it is available for reading. Look at the value of the isSuppor ted boolean property:

import flash.sensors.Accelerometer;
if (Accelerometer.isSupported == false) {

The accelerometer muted property is false if the user blocks access to the accelerometer sensor. Android devices do not provide an option to disable access at the time of this writing, so you can ignore it.

Now create an instance of the Accelerometer class. This is essential to make the accelerometer variable a class variable, not a local variable, to guarantee that it is not removed from memory:

var accelerometer:Accelerometer;
accelerometer = new Accelerometer();

Next, set an AccelerometerEvent to receive updates for the device sensor:

accelerometer.addEventListener(AccelerometerEvent.UPDATE, onUpdate);

A timer starts ticking the moment the application is initialized and returns a time stamp value in milliseconds. This is useful if you want to average activity over time:

function onUpdate(event:AccelerometerEvent):void {

The event returns a floating point for each axis that ranges between ‒1.0 and 1.0. The values indicate the force pulling your device from both gravity and the user’s motion. If your device is not moving, the only acceleration measured is gravity that is, of course, active.

Motion values are not locked into the default portrait aspect ratio. If the screen orientation changes, the Accelerometer class takes care of adjusting the values so that they are set according to the stage axis, not the device axis.


Please enter your comment!
Please enter your name here

Latest News

Top 10 Provinces of Thailand Not to be missed for Travel

10 SuratthaniThe source of the proverbial Chaiya salted egg. Surat Thani is a province with many attractions,...

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits, even though it will have...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

More Articles Like This