Search code examples
actionscript-3apache-flexair

Adobe AIR - Fullscreen / Display


Windows computer running AIR.

Every night the educational displays get turned off. The computers stay on.

On certain displays when they turn them on in the morning the screen resolution goes back and forth a few times starting at 1920 x 1080 then to 1024 x 768 then back to 1920 x 1080.

When this happens for some reason the AIR app freaks out and stays at 1024 x 768 which doesn't take up the fullscreen and you can see the desktop. We have to manually relaunch the AIR app.

Is there a way when this happens we can detect and go back to force Fullscreen?

Thanks in advance for any suggestions.


Solution

  • If you are using a maximized window, you can listen for Event.RESIZE on the stage (dispatched when the window get's resized), and or listen for the native windows displayStateChange or resize events.

    If you are using the FULL_SCREEN (or FULL_SCREEN_INTERACTIVE) display state, you can listen for the FullScreenEvent.FULL_SCREEN event to know when that has changed.

    Here is an example of a few things you can try:

    //in your document class or main timeline, listen for the following events:
    
    stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResized);
    //the above will fire anytime the window size changes, Really this is all you need as this event will fire when the window display state changes as well.
    
    stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, windowResized);
    //the above will fire anytime the window state changes - eg. Maximized/Restore/Minimize.  This likely won't trigger on a resolution change, but I've included it anyway
    
    stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullscreenChange);
    //the above will fire whenever you enter or leave fullscreen mode (stage.displayState)
    

    private function windowResized(e:Event):void {
        //re-maximize the window
        stage.nativeWindow.maximize();
    
        //OR Go to full screen mode
        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
    }
    
    private function fullscreenChange(e:FullScreenEvent):void {
        if (!e.fullScreen) {
            //in half a second, go back to full screen
            flash.utils.setTimeout(goFullScreen, 500);
        }
    }
    
    private function goFullScreen():void {
        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
    }