Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 - iOS force landscape mode only?

I've built a game for iOS that is designed for landscape mode and it works just fine except that if you turn the device to portrait mode it stops there to with the interface only filling about the middle half of the screen. How can I force the app to only allow the two landscape modes and not stop at the portrait position.

I've tried all the publishing settings. Aspect Ratio is set for Landscape and Auto Orientation is checked on, if I uncheck AUto Orientation that the app does not rotate to the other landscape mode and I hear that's an automatic rejection from Apple.

This app is ready to go except for this little flaw. Thanks for any help you can offer.

Rich

like image 491
Rich Avatar asked Jul 02 '11 19:07

Rich


2 Answers

I found the answer to this over on the Adobe forums a few days ago.

Set Aspect Ratio to Auto.

Set Auto Orientation to allowed.

Then use this code on your main clip:

var startOrientation:String = stage.orientation;
if (startOrientation == StageOrientation.DEFAULT || startOrientation == StageOrientation.UPSIDE_DOWN)
  {
    stage.setOrientation(StageOrientation.ROTATED_RIGHT);
  }
  else
  {
    stage.setOrientation(startOrientation);
  }                    

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

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

Worked fine for me..

like image 162
Eric M Avatar answered Sep 23 '22 02:09

Eric M


Another, albeit similar, way to do this is to set the aspectRatio to landscape in the application descriptor and autoOrients to false. Then enable autoOrients once the application has loaded and listen for the orientationChanging event. In Flash Builder 4.6, this may be done as follows:

Descriptor:

<aspectRatio>landscape</aspectRatio>
<autoOrients>false</autoOrients>

Application code:

private function applicationCompleteHandler():void {
    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, stageOrientationChangingHandler);
    stage.autoOrients = true;
}

private function stageOrientationChangingHandler(event:StageOrientationEvent):void {
    if (event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN) {
        event.preventDefault();
    }
}

It looks like you also have to make sure that the application has explicit dimensions; otherwise, views may still be resized even through the stage does not reorient.

Please see: http://bugs.adobe.com/jira/browse/SDK-32082

like image 38
BatFlexUser Avatar answered Sep 25 '22 02:09

BatFlexUser