Skip to main content
Known Participant
June 17, 2013
Question

Adobe air 3.4 + auto orient

  • June 17, 2013
  • 1 reply
  • 1515 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 19, 2013

Thank you very much for helping me with this.  More than likely i will be designing apps for the samsung tablet (for the next couple years at least) but need to have it able to deal with other devices as they pop up .  I'm currently learning this as I do this, so some of this will need to be "get it out there right now" fixes with the hopes of cleaning it up in later versions.


The store will bounce your app off if it doesn't play nicely with all devices that conform to the specs you require. For example if you say you support xlarge screens then it needs to work on almost all reasonable devices in this range. To force it to work on only higher end tablets, stick to requiring xhdpi and maybe even hdpi so the pixel density is high. In other words, it's not just a cheap $89 7" tablet because it will have a low end CPU, GPU and low pixel density (e.g., not a Galaxy). Otherwise you risk the store denying or pulling your app off if users complain.

You're welcome and if you're all set please mark any helpful/correct answers so we can filter unanswered. Good luck!