Peter Bosák
Peter Bosák

Reputation: 317

Changing AIR application screen orientation with device rotation - do different devices treat StageOrientation differently?

I want to make my AIR application change screen orientation along with the device rotation. However, I want to force it to be in landscape mode only - at no time do I want ti to be in portrait aspect ratio.

According to official Adobe documentation, one should do it like this: Change values in the descriptor file to this:

<aspectRatio>landscape</aspectRatio>
<autoOrients>true</autoOrients>

And then, in your code, do this:

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);

private function orientationChanging(e:StageOrientationEvent) {
    if (e.afterOrientation == StageOrientation.DEFAULT || e.afterOrientation == StageOrientation.UPSIDE_DOWN) {
        e.preventDefault();
    }
}

I've tested it on my tablet and it works flawelssly. However, somebody told me that different devices treat the StageOrientation values differently. In some cases, StageOrientation.DEFAULT is portrait and in others, it is landscape. That would make the above code do exactly the opposite of what I want to do. But I do not know if it's true or not.

Can anybody confirm? Do different devices treat the StageOrientation values differently?

Upvotes: 2

Views: 5053

Answers (2)

quarion
quarion

Reputation: 114

To force an app into landscape mode (while allowing it to go upside down) simply use:

stage.setAspectRatio(StageAspectRatio.LANDSCAPE);

And be sure to update your AIR SDK at least to 3.7 (or 3.8 beta). I have spend a lot of time on this issue, without any success - but simply updating the SDK solved it for me.

Upvotes: 3

user1901867
user1901867

Reputation:

You could try this to ensure landscape:

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);

private function orientationChanging(e:StageOrientationEvent)
{
    //if already in landscape, ignore change
    if (stage.stageWidth>stage.stageHeight)
    {
        e.preventDefault();
    }
}

Upvotes: 0

Related Questions