Skip to main content
August 11, 2011
Question

Dynamically change layout on orientation change

  • August 11, 2011
  • 1 reply
  • 498 views

Newbie to Flex in general as well as mobile, so this may be easy but I have not found an answer yet.

I have an app that will display 2 charts (pie and column) on a view. When the device is portrait, I want them to display with vertical layout. When landscape, they should display with horizontal layout. How do I accomplish that?

Thanks in advance.

This topic has been closed for replies.

1 reply

relaxatraja
Inspiring
August 11, 2011

check for your stage width/height on orientations using the following listener:

import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;

stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;

stage.addEventListener(Event.RESIZE,resizeHandler);

function resizeHandler(e:Event):void{
            outputTxt.text="Stage Size: " + this.stage.stageWidth+"-"+this.stage.stageHeight+
                                            "\nDevice Orientation: " + this.stage.deviceOrientation;
            positionAll();                                           
}

hope this helps

August 11, 2011

Not exactly what I am looking for. I know how to listen and respond to an orientation change event. What I don't know how to do is

  1. when the app switches to Portrait mode, place the items in a Vertical Layout.
  2. when the app switches to Landscape mode, place the items in a Horizontal Layout.

Is this feasible? I can't have both a HGroup and a VGroup and select them using states (I don't think) so I am thinking of perhaps a Group which alternates its selection of a VLayout or HLayout.