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

Switching between portrait and landscape based upon device tilt

Most Android devices will allow both portrait and landscape views for the user to interact with. The portrait mode is enabled when the device is held with the y-axis aligned from top to bottom, while landscape mode is enabled by holding the device so that the y-axis is measured from left to right. By using data reported from the accelerometer sensor, we can know when these movements have occurred and respond to them within our application.

How to do it...

We will need to employ the Accelerometer API to detect device rotation and tilt:

  1. First, import the following classes into your project:
    import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import ...

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