Handle screen orientation event

Hello, I want to use window.screen.orientation.onchange function to handle screen orientation event on html5 project,
https://www.openfl.org/learn/npm/api/pages/js/html/ScreenOrientation.html

how can I get the “window” instance in haxe?

I I prefer to use the stage resize event which gives me more control over screen changes, especially desktop browser resizing, which can also be used to identify orientation changes. Like this:

// initializing the application
public function new() {
  if (this.stage == null) {
    this.addEventListener(Event.ADDED_TO_STAGE, this.onStage);
  } else {
    this.onStage();
  }
}

// the stage is available
private function onStage(evt:Event = null):Void {
  if (this.hasEventListener(Event.ADDED_TO_STAGE)) {
    this.removeEventListener(Event.ADDED_TO_STAGE, this.onStage);
  }
  this.stage.addEventListener(Event.RESIZE, onStageResize);
}

// from here you can check your screen orientation change
private function onStageResize(evt:Event):Void {
  
}
1 Like

I found it. Browser.window.