• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

prevent landscape

Participant ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

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?

TOPICS
Development

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 20, 2011 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 StageO

...

Votes

Translate

Translate
Participant ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

spoke to soon

still looking!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

Thanks colin, I can confirm that the following works

I thought prevent Default literally meant prevent the default screen setting but I now realise it means prevent what it is trying to be.

With regard to iPAD apps having to be rotatable though, I had read this too but I have 2 iPAD apps that have no auto rotation at all on the app store and neither were rejected.

Joe

import flash.display.StageOrientation;

var startOrientation:String = stage.orientation;

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

{

}

else

{

stage.setOrientation(StageOrientation.DEFAULT);

}

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

function orientationChangeListener(e:StageOrientationEvent)

{

if (e.afterOrientation == "rotatedLeft" || e.afterOrientation == "rotatedRight")

{

e.preventDefault();

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

Yes, it can be confusing. preventDefault prevents the default action, not the default orientation.

Glad your non-rotating apps got accepted. Sometimes it's obvious from the style of the app that rotating would be a bad thing. For example, in a ball/maze like game, having the whole area rotate on you might ruin things. In an app I did that had a couple of mini games in it, I allowed rotation every except in the games.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2011 May 20, 2011

Copy link to clipboard

Copied

For one of those apps that was true for sure, it was a spinner that didn't need a rotation because it was looking at a birds eye view. but my other app had not such restrictions, I only read about the rotation policy after i had submitted it, so was expecting it to be rejecting, was pleased when it wasn't

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

I was looking at this yesterday but what I could gather

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

is only supported on a few devices and didn't work on mine....

I did evenually found this: http://help.adobe.com/en_US/as3/dev/WS901d38e593cd1bac1c39723e12caaf5620c-8000.html

Though lots of other places implied it would work.....

Couldn't find a solution to having AutoOrientate as true but fixing it in the code without having two versions of each screen depending on orientation, and even then if using

stage.scaleMode = StageScaleMode.NO_SCALE;

then have issues with different size screens....

Eddie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

There isn't a changing even on Android, and some people work around that by having auto orient turned off, and doing the orientation themselves by watching the accelerometer. It should always work on iOS devices though.

@joeboy, just yesterday I heard of a case where someone did an update to an app in the App Store, where both the original and the update only did one type of landscape. The original managed to get accepted, but the update was rejected because it only supported one of the two landscapes. So, in your case either never update the app, or if you do, be prepared to let the app orient itself at first, and then do the preventdefault when you get into the actual game play.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

@ colin Actually i had already updated the app and didn't change the orientation, it still got accepted though.

maybe i just got lucky twice?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

Yes, I think so. Or the tester likes you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

The orientation changing event is never dispatched by Android devices.

As for scale mode, even if you use noScale, you still have the option of scaling your content manually by setting the scale factors of the root sprite object.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2011 May 24, 2011

Copy link to clipboard

Copied

When I said there isn't a changing event on Android, I meant there isn't a changing event on Android, not that there is one and that Flash doesn't let you have it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 26, 2011 May 26, 2011

Copy link to clipboard

Copied

"The orientation changing event is never dispatched by Android devices."

What about the Playbook?

Eddie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 27, 2011 Jun 27, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jun 27, 2011 Jun 27, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 27, 2011 Jun 27, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 27, 2011 Jun 27, 2011

Copy link to clipboard

Copied

LATEST

Correction: You don't have to set this on a view-by-view basis. In my case I only want the autoOrient to work on one view. So when that view activates I set stage.autoOrient = true. Then when that view deactivates I set it back to false. Nice and easy.

Thanks again James.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines