I'm not sure if this is right, I did something wrong at the end, but after a big fight, I found this to be a stable solution:
private function onAddedToStage(event:Event):void { if (stage.autoOrients) { stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging); stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging, false, 100, true); } } private function orientationChanging(event:StageOrientationEvent):void { event.stopImmediatePropagation(); if (event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN) { event.preventDefault(); } }
First of all, it should be noted that addToStage works several times (2-3) in the mobile application. I do not know why, in the code there is no addChild. Perhaps the AIR runtime is doing something else. Thus, in order to avoid adding an unnecessary number of handlers, the general technique is to remove the handler first - it will not do anything if such a handler is not registered yet, but if it is, it will delete it, which will keep the handler counter at 1.
Secondly, the priority of the event is that it will not work at 0, it must be set to something big in order to be launched in front of the file during AIR execution.
The last thing is event.stopImmediatePropagation () - now that we are the first to process the event, we cannot prevent this event, which will be sent further in this particular scenario.
This together makes an orientation that prevents impeccable work - for me, the landscape and the reverse landscape (rotated_left, rotated_right) worked and switched, and portrait modes did not affect the presentation at all.
Now there is a danger: you can remove the listener after exiting the view (at the end of the transition animation, deactivate the view or something else), because stopImmediatePropagation will prevent the event from being processed in other parts of your application.
I hope that Adobe (or Apache now, actually) will look more closely at this problem and track my solution.
EDIT
Here's the last problem with this solution, if the application starts when the device is in the DEFAULT or UPSIDE_DOWN orientation, in this case the application will be in portrait mode.
To fix this, you need to change the aspect ratio in the addToStage handler:
if(Stage.supportsOrientationChange) { stage.setAspectRatio(StageAspectRatio.LANDSCAPE); }