Skip to main content
Known Participant
June 17, 2013
Question

Adobe air 3.4 + auto orient

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

it does appear that the device that this app will be used on most (Samsung Galaxy Tab 2 10.1) has landscape as it's default.  to get it to work - for right now - i just reversed the code for the default and rotated left/right.  down the road I will have to get this to work on other devices (and possibly iPads), so I will need to do less hard coding.  In order to do this, what would be the most effective way?  I have a header image that I could reliably (based on any device) set a zeroes (x and y).  Should I base all other screen items off of that, or try using stage commands (stage.width/2) etc.?


Having not known the devices you want this to be on, I'd go back to simply measuring the devices resolution width versus height and translate that into landscape or portrait. All you calculations should be based on the returned resolutions for placement of items. It will require somewhat of a layout engine and for you to clearly mark what device resolutions you support.

For instance it's pretty easy to handle Apple because you're really only dealing with 1024x768 or 2046x1536 and portrait is DEFAULT. However if you're just measuring device width and height, you'll still get the same result, portrait, from your measurements.

Android is really rough but gives you more granular control over the minimum and maximum size and resolution of the device. You can clearly mark in your apps android settings that you only support say, 7"-10" devices with a resolution of a certain size (marked as ldpi, mdpi, hdpi, xhdpi). For more info and what all those settings mean, read here: http://developer.android.com/guide/practices/screens_support.html

  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

Staying inside xlarge keeps you in the 7-10" safe range for a larger tablet like the Galaxy.