O'Reilly logo

Developing Android Applications with Adobe AIR by Véronique Brossier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Accelerometer

You may hate gravity, but gravity does not care.

Clayton Christensen

The ability to detect motion opens a world of possibilities for interaction and game design. Motion sensor technology can be used to create an intuitive, life-like user interface, a control mechanism in gaming, or a new kind of brush for animation.

In this chapter we will discuss how to detect motion, and we will go over some examples that make use of this information.

What Is a Motion Sensor?

Your Android device contains an onboard sensor that measures acceleration along the perpendicular axes—on the x-axis from left to right, on the y-axis from bottom to top, and on the z-axis from back to front. It calculates the forces affecting the device, both gravity and user movement. Figure 8-1 depicts acceleration measurement along the perpendicular axes on an Android device.

Measuring acceleration along the perpendicular axes on an Android device
Figure 8-1. Measuring acceleration along the perpendicular axes on an Android device

The Accelerometer Class

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 EventDispatcher class. The flash.events.AccelerometerEvent class is a new Event class that returns the sensor’s updated information.

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required