Change View State Based On Screen Orientation?
I'd like my app to change layouts based on the current screen orientation. I believe this is done through view states. I have three questions...
1) How do I check the current orientation?
2) Is there an event listener that will tell me when the orientation changes?
3) How do I toggle between view states?
Thank in advance!
UPDATE: I figured out the answer to question 3...
currentState = 'yourStateName';
UPDATE II: I figured out the answer to question 1 as well. I simply used the Capabilities object to determine the screens current width & height, then compare the two. All of this is in a function that gets called when the app launches:
public function checkOrientation():void {
var screenWidth:Number = Capabilities.screenResolutionX; var screenHeight:Number = Capabilities.screenResolutionY;
if (screenWidth > screenHeight) {currentState='yourStateName1';} else if (screenWidth < screenHeight) {currentState='yourStateName2';}
}
Now all I have to do is figure out how to call this function when there is an orientation change. I tried the code below but get the included error:
stage.addEventListener(Event.RESIZE, checkOrientation); // ERROR: Access of undefined property stage
