1

I'm creating an app that will have a different menu if the phone is held landscape, or portrait.

I figure I have to tell flash to move to a new frame when the phone moves from landscape to portrait or vice versa, but I'm not sure the exact code to after creating the orientation event listener.

2 Answers2

1

There are two ways. Listen for a StageOrientationEvent or listen for Event.RESIZE. I personally prefer to use RESIZE as it is called slightly more often and keeps your interface in sync more.

var landscapeNav:Sprite; // this would be your landscape nav. Obviously does not have to be a Sprite
var portraitNav:Sprite; // same as landscapeNav, but this represents your portrait nav
stage.addEventListener( Event.RESIZE, this.stageResizeHandler );

function stageResizeHandler( e:Event ):void {
    if ( stage ) { //just to make sure the stage is loaded in this class so we avoid null refs
        if ( stage.stageWidth >= stage.stageHeight ) {
            landscapeNav.visible = true;
            portraitNav.visible = false;
        }
        else {
            landscapeNav.visible = false;
            portraitNav.visible = true;
        }
    }
}

This could definitely be cleaned up (landscapeNav.visible = stage.stageWidth > stage.stageHeight) but this should give you something to go on. If you want to do an animation as Atriace suggested, you would do a TweenLite/Max call within the conditional in the function instead of setting visible to true/false (after the animation is done, though, you should set visible to false just for the same of optimzation)

Josh
  • 8,079
  • 3
  • 24
  • 49
  • Hey thanks for the replies. The code i ended up using was: `stop(); //finds out when orientation is changed stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onChange); function onChange(e:StageOrientationEvent):void { gotoAndStop(3); }` – Shaun Jeffries Mar 29 '13 at 14:00
0

You don't need to create a new frame. In fact, it may be more visually appealing to watch the old menu slide off, and the new one to animate in (like with TweenLite).

The documentation on orientation change can be found @ Adobe's ActionScript APIs specific to mobile AIR applications: "Screen Orientation", and the API.

Atriace
  • 2,572
  • 1
  • 14
  • 27
  • The problem with the orientation in AS3 is that everything is relative to the DEFAULT position of the device. This changes between landscape and portrait from device to device so there is no real way of knowing what to look for. See [my answer here](http://stackoverflow.com/questions/15346702/as3-air-if-phone-use-portrait-if-tablet-use-landscape/15349616#15349616) for a better explanation of this. – Josh Mar 28 '13 at 16:31