Skip to main content
Inspiring
May 20, 2011
Answered

prevent landscape

  • May 20, 2011
  • 2 replies
  • 2965 views

So I know that I can add this code to prevent portrait mode

import flash.display.StageOrientation;

var startOrientation:String = stage.orientation;

if (startOrientation == "default" || startOrientation == "upsideDown")

{

stage.setOrientation(StageOrientation.ROTATED_RIGHT);

}

else

{

stage.setOrientation(startOrientation);

}

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

function orientationChangeListener(e:StageOrientationEvent)

{

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

{

e.preventDefault();

}

}

What is the landscape equivalent of preventDefault? I have cs5.5 so am using air 2.6. I know before there was a workaround where you could set the publish orientation to landscape but i assume you don't need to do this now?

This topic has been closed for replies.
Correct answer Colin Holgate

Although what you say is true, it's a requirement of iPad apps that you support the variations of the needed orientations. That is, you're not allowed to penalize someone who likes to operate their iPad with the home button at the top.

As for checking landscape, you could either use the checks for portrait and do nothing, but do a preventDefault in the Else part of the If statement, or you can use the constants instead of string for checking. So, look for StageOrientation.ROTATED_RIGHT and StageOrientation.ROTATED_LEFT instead of "rotatedRight" and "rotatedLeft". Just in case the strings aren't what you think they are.

2 replies

Participant
June 28, 2011

I have a problem where I need to have autoRotate on for just a few views in my app - the ones with youTube videos. The others all need to be portrait. I think I solved this for Android:Listen for the stage resize stage.addEventListener( Event.RESIZE, onOrientationChange ); And then set the set the orientation: stage.setOrientation( StageOrientation.DEFAULT ); in the handler.

Seems to work so far. Now I can enable/disable autoRotate on a view-by-view basis.

Participating Frequently
June 28, 2011

Change the value of Stage.autoOrients to true in views that need to auto orient and false in the others.

Participant
June 28, 2011

Shhhhwing... That's much better. Thanks James! Although it's stage.autoOrients = false. not Stage.auto... ( lowercase )

Also, anyone looking to set stage.autoOrients on a view by view basis will have to wait for the ApplicationComplete event to set this on the initial view. It can be set on all of the other views at viewActivate or creationComplete.

joeboy_ukAuthor
Inspiring
May 20, 2011

spoke to soon

still looking!

May 20, 2011

If you want your entire app to be in portrait mode without the possibility of landscape.. in cs5 and cs5.5 (assuming you are using flash pro) in the publish settings there is an "Auto orientation" setting in the general tab.  If you don't check that, the app will always be in portrait and not rotatable.  If you want the ability to switch back and forth and lock it at certain time, i am not sure atm.

Colin Holgate
Colin HolgateCorrect answer
Inspiring
May 20, 2011

Although what you say is true, it's a requirement of iPad apps that you support the variations of the needed orientations. That is, you're not allowed to penalize someone who likes to operate their iPad with the home button at the top.

As for checking landscape, you could either use the checks for portrait and do nothing, but do a preventDefault in the Else part of the If statement, or you can use the constants instead of string for checking. So, look for StageOrientation.ROTATED_RIGHT and StageOrientation.ROTATED_LEFT instead of "rotatedRight" and "rotatedLeft". Just in case the strings aren't what you think they are.