AS3 - iOS landscape mode only?

I built an iOS game designed for landscape mode, and it works great, except that if you switch the device to portrait mode, it stops there when the interface fills only in the middle of the half of the screen. How to make the application allow only two landscape modes and not stop in portrait position.

I tried all publishing settings. Aspect Ratio is set to Landscape and Auto Orientation, if I disable AUto Orientation so that the application does not rotate in a different landscape mode, and I hear that Apple automatically rejects.

This application is ready to use, with the exception of this slight flaw. Thanks for any help you can offer.

Rich

+6
source share
3 answers

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

Set aspect ratio to auto.

Set the allowed auto orientation.

Then use this code in the 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 well for me ..

+11
source

Another, albeit similar, way to do this is to set aspectRatio to the terrain value in the application descriptor and autoOrients to false. Then enable autoOrients as soon as the application loads, and listen for the orientationChanging event. In Flash Builder 4.6, this can 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 should also make sure that the application is explicitly sized; otherwise, views can be changed even through the stage, not reoriented.

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

+2
source

The answer above did not help me, because on iOS the preventDefault function no longer works.

For those who just don't have luck yet ... That's what I did.

I wanted:

IPad and all Android Tablet devices to be able to portrait or landscape and automatically rotate in any direction

Iphones, Ipods and All Small Screen Devices will be forced to move around the landscape (or maybe in your case you need a forced portrait).

I did:

In my -app.xml:

 <aspectRatio>any</aspectRatio> <autoOrients>true</autoOrients> 

In Actioncript:

  var screenDPI:Number = Capabilities.screenDPI; var resolutionX:Number = Capabilities.screenResolutionX; var resolutionY:Number = Capabilities.screenResolutionY; var numDiagonalDistance:Number = Math.round(Math.sqrt((resolutionX*resolutionX)+(resolutionY*resolutionY))); var numDiagonalInches:Number = numDiagonalDistance/screenDPI; if(numDiagonalInches<6){ MainData.SMALL_DEVICE=true; }else{ MainData.SMALL_DEVICE=false; } if(MainData.SMALL_DEVICE){ this.stage.setAspectRatio(StageAspectRatio.LANDSCAPE); } 

Although I think you could easily put StageAspectRatio.PORTRAIT or even use the reverse logic only for logical ipads or something else. Good luck

EDITED: I am really editing this because even this method still has problems. You will get a landscape, but it’s not always a landscape focused on how you hold the device ...

EDIT AGAIN (2-27-2014): It turns out that if I turned on -swf version 23 (now with AIR 4.0), this problem is finally resolved.

+1
source

Source: https://habr.com/ru/post/891884/


All Articles