Skip to main content
Participating Frequently
July 6, 2011
Question

Lock orientation AIR 2.7 Android

  • July 6, 2011
  • 3 replies
  • 2275 views

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 has been closed for replies.

3 replies

jerome2Author
Participating Frequently
July 11, 2011

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

Next up packaging for BB Playbook

Cheers,

J.

Inspiring
July 11, 2011

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

jerome2Author
Participating Frequently
July 11, 2011

Hi Boat5,

I meant the Samsung Galaxy Tab not the Viewsonic gTab

Cheers,

J.

relaxatraja
Inspiring
July 6, 2011

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();

}             

}

jerome2Author
Participating Frequently
July 6, 2011

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.

jerome2Author
Participating Frequently
July 6, 2011

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.