Posts tagged ‘WindowedApplication’

Center AIR Window on the screen

You might have noticed that Window or WindowedApplication doesn’t load in the center of your screen. By default, window loads somewhere in the left side on your desktop. I personally think, that this is a bad user experience and you should always center window vertically and horizontally on screen. You can do this by setting window x coordinate to (screen.width – window.width)/2 ¬†and y coordinate to (screen.height – window.height)/2.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="" layout="absolute"
    creationComplete="centerWindow(this)" viewSourceURL="srcview/index.html"> 

            import mx.core.Window;

            private function centerWindow(window:WindowedApplication):void
                var screenBounds:Rectangle = Screen.mainScreen.bounds;
                var nativeWindow:NativeWindow  = window.nativeWindow;

                nativeWindow.x = (screenBounds.width - nativeWindow.width)/2;
                nativeWindow.y = (screenBounds.height - nativeWindow.height)/2;