Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AIR mobile always in landscape

I am making an app in AIR mobile that I need to be in landscape mode all the time. On most devices this is OK, but on some devices (Motorola XOOM for example) the app launches in landscape. At least on the build in emulator that comes with Flash Builder 4.5. I don't know if this is a problem with the emulator or if the XOOM has different orientations than most devices. Anyway, I want to make sure that the device is always in landscape mode. This can be checked easily:

if(stage.stageWidth<stage.stageHeight){
 //rotate screen;
}

What do I need to put in if statement to make sure that it is properly oriented?

Thanks.

like image 693
Petre Popescu Avatar asked Jan 19 '26 22:01

Petre Popescu


2 Answers

In the *-app.xml file you can define how application should act:

<aspectRatio>landscape</aspectRatio>
<autoOrients>true</autoOrients>
like image 106
Jevgenij Dmitrijev Avatar answered Jan 22 '26 16:01

Jevgenij Dmitrijev


Even with aspectRatio set to landscape and autoOrients set to false in application.xml, sometimes a device's orientation is incorrectly set during the first frame of a mobile air 3.1 app, so stage.stageWidth will return the smaller of the two dimensions. Several frames later it will flip to the correct orientation. This could be what you witnessed.

So if you need to know the landscape stage dimensions when your app first loads, use:

var width :Number = Math.max(stage.stageWidth, stage.stageHeight);
var height :Number = Math.min(stage.stageWidth, stage.stageHeight);

You should not need to rotate your entire app manually, but here's how:

this.rotationX = 90
like image 45
Sarah Northway Avatar answered Jan 22 '26 16:01

Sarah Northway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!