Home » ActionScript 3.0, AIR

Center an Adobe AIR application on Screen

21 June 2009 One Comment
Share on Facebook

By default NativeWindow loads some where on the screen. Loading an splash screen or application on center of the screen will gives better user experience.

Below code we are creating a native window and aligning in the screen center.

var _splashWindow:NativeWindow = new NativeWindow(nativeWindowOptions);

_splashWindow.width = 484;

_splashWindow.height = 289;

_splashWindow.stage.align = "TL";

_splashWindow.stage.scaleMode = "noScale";

_splashWindow.title = "Center on screen";
var screenBounds:Rectangle = Screen.mainScreen.bounds;

_splashWindow.x = (screenBounds.width - _splashWindow.width)/2;

_splashWindow.y = (screenBounds.height - _splashWindow.height)/2;
_splashWindow.activate();

Here,

var screenBounds:Rectangle = Screen.mainScreen.bounds;

Screen.mainScreen.bounds return the screen boundary.

_splashWindow.x = (screenBounds.width - _splashWindow.width)/2;

_splashWindow.y = (screenBounds.height - _splashWindow.height)/2;

Centering the application on screen.

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


  • Ed

    Hi, I am new to AIR and quite new to Flash (roots in DIrector Lingo programming). I just cant get my air app to center on the screen when it opens. If I were to use the code above where do I put it? I cant believe that center on screen is not a preset tick box function on the AIR settings.. surely its a standard requirement.

    Any hep would be great! Thanks.