Skip to main content
Known Participant
June 17, 2013
Question

Adobe air 3.4 + auto orient

  • June 17, 2013
  • 1 reply
  • 1541 views

I'm having trouble with getting the app I'm creating (using Flash professional CS6) to auto orient reliably.  if the app is moved from portrait to landscape, it works fine.  when moved back from landscape to portrait, then the screen items do not move to the desired spots.  within each of the "if" statements I also have commands for setting where screen items within the milApp movie clip are to appear.  Any help is greatly appreciated.

//function to set the stage orientation for the app;

function orientMilApp(event:Event):void

{

    var device_width:int = appStage.stageWidth;

    var device_height:int = appStage.stageHeight;

    if (device_width > device_height)

    {

        milApp.gotoAndStop("landscape");

        //set the height, width, and position of the cheat sheet;

        milApp.cheatSheet_mc.x = 0;

        milApp.cheatSheet_mc.y = 100;

        milApp.cheatSheet_mc.height = 1657.25;

        milApp.cheatSheet_mc.width = 1280;

        milApp.closeButton_btn.x = 1200;

        milApp.closeButton_btn.y = 101;

        //set the dimensions and position of screen items for the driver manual

        //set the dimensions and position of screen items for the reference manual

      } else {

        milApp.gotoAndStop("portrait");

        milApp.closeButton_btn.x = 720;

        milApp.closeButton_btn.y = 101;

        //set the height, width, and position of the cheat sheet;

        milApp.cheatSheet_mc.x = 0;

        milApp.cheatSheet_mc.y = 100;

        milApp.cheatSheet_mc.width = 800;

        milApp.cheatSheet_mc.height = 1035.80;

        //set the dimensions and screen items of the driver manual

        //set the dimensions and screen items of the reference manual

        }

}

appStage.addEventListener (StageOrientationEvent.ORIENTATION_CHANGE, orientMilApp);

This topic has been closed for replies.

1 reply

sinious
Legend
June 17, 2013

Initially I'd just recommend a couple things and need a little more info as well.

First I'd use the StageOrientation class to determine landscape or portrait, e.g.:

if (stage.orientation == StageOrientation.DEFAULT || stage.orientation == StageOrientation.UPSIDE_DOWN)

{

  // portrait

}

else if (stage.orientation == StageOrientation.ROTATED_LEFT || stage.orientation == StageOrientation.ROTATED_RIGHT)

{

  // landscape

}

else if (stage.orientation == StageOrientation.UNKNOWN)

{

   // device is unable to determine (laying down? not activated/initialized yet?), check event later

}

Aside that what is your stage.align and stage.scaleMode set to? X/Y coordinates will change if you didn't anchor it to something like TOP_LEFT and NO_SCALE.

Mordred58Author
Known Participant
June 17, 2013

i do have it anchored using TOP_LEFT and NO_SCALE.  will i need to create a new class (.as file) to call the stage orientation class?

sinious
Legend
June 17, 2013

You just need to import it if you haven't (the word is linked to the class in my post, flash.display.StageOrientation). They're just constants set up for ease of use.

Also you should always try to use the correct event type so you have properties you expect available so you should change that event handler signature from event:Event to: function orientMilApp(event:StageOrientationEvent):void

You're using explicit values for positioning (milApp.cheatSheet_mt.y = 100, etc). That's really hard wired to the device you're debugging on. Is that your actual intention? The app won't really be usable on any other device that doesn't conform to your numbers and expected resolution/form factor. If it's a personal app then it's even still a good idea to consider getting the devices resolution and basing your positioning on that rather than hard coding it.

Aside that can you explain more about what isn't positioning correctly and/or show any screenshots?