Skip to main content
Participating Frequently
Jul 6, 2011 7:43 AM UTC
Question

Lock orientation AIR 2.7 Android

Hi,

I working on an app where I want to respond to the device rotation changes but I want the stage to remain in the statting landscape mode.

I listen to StageOrientationEvent.ORIENTATION_CHANGING on the stage and preventDefault once I updated the app. This behavior woks when I test on the desktop. But on the devices (gTab and Atrix) the stage still re-orients.

autoOrient is set to true in the xml. aspectRation is set to landscape. Setting autoArient to false means the StageOrientationEvent never fires.

What am I missing?!

private function onStageOrientationChanging( e:StageOrientationEvent 😞void

{

                    // do my stuff & kill event

                    e.preventDefault();

          }

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

jerome2Author
Participating Frequently
Jul 11, 2011 6:53 AM UTC

For those interested here's the final project: http://www.countthedots.com/

Next up packaging for BB Playbook

Cheers,

J.

Translate
Inspiring
Jul 11, 2011 1:37 AM UTC

Jerome, can you tell me how you got Adobe Air running on the gTab and if its stable? (viewsonic gtab right?) I have read of the 'market fix' but also read of issues with Air on gTab.

Is there a specific rom i should put on it? My father owns one and would like me to install Air and all its glory!

thanks

Translate
jerome2Author
Participating Frequently
Jul 11, 2011 6:52 AM UTC

Hi Boat5,

I meant the Samsung Galaxy Tab not the Viewsonic gTab

Cheers,

J.

Translate
relaxatraja
Inspiring
Jul 6, 2011 8:51 AM UTC

Try this:

import flash.display.StageOrientation;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.align = StageAlign.TOP_LEFT;

var startOrientation:String = stage.orientation;

if (startOrientation == "default"){

stage.setOrientation(StageOrientation.ROTATED_RIGHT);

}

if (startOrientation == "upsideDown"){

stage.setOrientation(StageOrientation.ROTATED_LEFT);

}

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

function orientationChangeListener(e:StageOrientationEvent){

if (e.afterOrientation == "default" || e.afterOrientation == "upsideDown"){

e.preventDefault();

}             

}

Translate
jerome2Author
Participating Frequently
Jul 6, 2011 9:49 AM UTC

Hi Relaxatraja,

In theory this should work, but I have found the root of the issue: "ORIENTATION_CHANGING events are not dispatched on Android devices."

Since ORIENTATION_CHANGE is not cancelable this means you can't prevent the default behavior on Android. The device will auto-orient unless you disable it in the XML... FML.

Unless someone has a work around, I will post a bug report or feature request

Cheers,

J.

Translate
jerome2Author
Participating Frequently
Jul 6, 2011 12:17 PM UTC

I figured out a workaround:

1- set autoOrient to false in the xml

2- in an accelerometer event or ENTER_FRAME event check the stage.deviceOrientation. This returns the state of the device exactly as stage.orientation would if you had autoOrient to true in the XML.

It's a hack, but it works. The stage doesn't re-orient and I get the device orientation to update the elements in my app

Cheers,

J.

Translate