Flex mobile orientation: force portrait mode and then allow auto orientation
I'm creating a flex mobile project and I want to force the app to portrait orientation when I click a button, and when I click other button allow again to change the orientation.
This is my code when I click the first button, where I want to force portrait mode:
protected function click(event:MouseEvent😞void{
if(stage.orientation != StageOrientation.DEFAULT){
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChanged);
stage.setOrientation(StageOrientation.DEFAULT);
}else{
doSomething();
}
}
private function orientationChanged(event:StageOrientationEvent😞void{
doSomething();
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChanged);
}
private function doSomething():void{
stage.autoOrients = false;
}
It works ok and it changes the orientation if it's needed.
Now, when I want to allow orientation change again, I've only putted:
stage.autoOrients = true;It works ok if when I click the first button the app is in portrait and it doesn't have to change anything. But if it's on landscape and it have to change to portrait, when I allow orientation change again, it doesn't work ok.
Do you know if I have to allow or change something? Or, is there any better way to do this?
Thanks in advance
