I'm developing an app with a default orientation set to Portrait in Flash Air for iOS settings; and the auto orientation is off.
However after adding a certain movieClip I want it to detect if the orientation changes and then change its position for a landscape or portrait display.
The problem is that StageOrientationEvent.ORIENTATION_CHANGE wont be dispatched if I disable the auto orientation. And even if it is enabled, the listener will only dispatch when the orientation changes to upside down or default (not landscapes)
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.events.StageOrientationEvent;
import flash.display.StageOrientation;
import flash.events.Event;
public class NoteBook extends MovieClip
{
public var type: String = new String();
public var deviceHeight: Number = new Number();
private var nbp: NoteBookPic;
public function NoteBook(DeviceHeight: Number = 720)
{
nbp = new NoteBookPic();
this.addChild(nbp);
nbp.deviderPic.visible = false;
this.deviceHeight = DeviceHeight;
this.x = 0;
this.y = deviceHeight / 2;
this.scaleY = (deviceHeight / 720) * .65;
this.scaleX = this.scaleY;
this.addEventListener(MouseEvent.CLICK, clicked);
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
public function exit()
{
this.removeEventListener(MouseEvent.CLICK, clicked);
this.stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orient);
this.parent.removeChild(this);
}
private function clicked(e: MouseEvent)
{
}
private function addedToStage(e: Event)
{
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
this.stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orient);
}
private function orient(e: StageOrientationEvent)
{
trace(e.beforeOrientation, e.afterOrientation)
}
}
}
UPDATE:
I just read in ActionScript® 3.0 Reference for the Adobe® Flash® Platform that StageOrientationEvents are only dispatched for device rotation when autoOrientation is true; but as I mentioned above even if it is enabled, the listener will only dispatch when the orientation changes to upside down or default (not landscapes). Which in my case is a problem as my app must be a portrait app except for that very MovieClip when on my stage. And when it is on stage I want it to react to any orientation changes, two portraits and two landscapes.