O'Reilly logo

Flash Development for Android Cookbook by Joseph Labrecque

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

Updating display object position through accelerometer events

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.

How to do it...

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

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