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?

Mordred58Author
Known Participant
June 19, 2013

It's why trying to be device agnostic is so important, which means staying away from specifics as much as possible. Things like hard coding resolution or using features on devices that aren't yet extremely common (NFC, etc).

Your device very well may consider DEFAULT/UPSIDE_DOWN to be what you call landscape. I haven't verified it but it would make sense on something like one of my old ASUS Transformers that're HD aspect displays. You'd probably consider holding it like a HD display (wide) before holding it thin and tall, so the default could be landscape.

So get used to just measuring what the device reports as the area you have available and then you'll need some layout logic to best use that space. Having said that, perhaps you'd want to go back to detecting if the available width or height is greater to handle that situation how you see fit.

Is the orientation change event firing off for you at all? If so are you tracing the stage.orientation property to see what it thinks the orientation is?


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.?