0
votes

I'm testing my starling application on iPhone 4, I suspect this is happening because of the obsolete IOS version.

package
{

    import flash.events.Event;
    import flash.events.StageOrientationEvent;
    import flash.display.Sprite;

    public class Startup extends Sprite
    {

        public function Startup():void
        {
            addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        }

        private function onAddedToStage(e:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

            stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);
        }

        private function orientationChangeListener(e:StageOrientationEvent):void
        {
            Debug.write("orientation: " + stage.orientation); //Never called
        }

    }

}

application.xml has autoOrients set to "true" and aspectRatio set to "landscape", I also tried deleting aspectRatio as suggested in some stackoverflow answer, to no avail.

StageOrientationEvent.ORIENTATION_CHANGING is never dispatched in my application.

Another weird thing is happening, which might help you understand the situation better:

Even though aspectRatio is set to "landscape" in application.xml, the app opens in portrait mode, and stage.orientation returns "rotatedRight" (meaning landscape). I can only set to landscape properly by setting aspectRatio to "portrait" in application.xml, and then manually setting to "landscape" in runtime:

stage.setOrientation(StageOrientation.ROTATED_RIGHT);
2
what's your AIR SDK version ? I've experienced a lot of problems two years ago with orientation when developing a universal phone/tablet app, with a vertical layout on phone, horizontal on tablet. Since then, I haven't messed anymore with dynamic orientation, and sticked with static orientation defined in application descripto, but I've seen several times bugfixes about orientation in various AIR SDK release notesjauboux
AIR 18.0. I want to lock the orientation to landscape only (which still changes between rotatedRight and rotatedLeft), but simply specifying that in application.xml doesn't do the trick, so I'm resorting to manually detecting the orientation change.Royi Bernthal
Since there was a mistake in the posted code I need to delete my answer now.BotMaster
un deleted my answer and changed its contents.BotMaster

2 Answers

0
votes

If all you want is to lock landscape mode then first in description XML set aspectRatio to landscape and autoOrient to true then in code do:

stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
stage.autoOrients = true;

And the device will not go through portrait.

0
votes
    <autoOrients>true</autoOrients>
    <aspectRatio>landscape</aspectRatio>

should be the way to gay, it has always worked for us but we dont have published apps using this setting with air sdk 18

since it seems that it doesnt work for you, you may try the dynamic way as a workaround, like we use in our universal build (detects device iphone/ipad in preloader frame, applies correct orientation, instantiates the right main class), tested on old devices/os versions

with

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

and call stage.setAspectRatio(StageAspectRatio.LANDSCAPE); asap, meaning right in you main or preloader class constructor