views:

38

answers:

2

In my application.xml I can set the position of the initial window. However this is set in pixels from the top left corner of the screen.

So how would I centre it?

+1  A: 

put this into application's creationComplete event handler

var screenBounds:Rectangle = Screen.mainScreen.bounds;
nativeWindow.x = (screenBounds.width - nativeWindow.width) / 2;
nativeWindow.y = (screenBounds.height - nativeWindow.height) / 2;
afftee
Sorry, should have mentioned I need to do it using Javascript.
Ben Shelock
+1  A: 

Try this one(this is JavaScript):

var bounds = null;
var screen = air.Screen.mainScreen.visibleBounds;

bounds = new air.Rectangle(
    (screen.width - WINDOW_WIDTH ) / 2,
    (screen.height - WINDOW_HEIGHT) / 2,
    WINDOW_WIDTH,
    WINDOW_HEIGHT
);

htmlLoader.stage.nativeWindow.bounds = bounds;
afftee
WINDOW_WIDTH and WINDOW_HEIGHT were not defined by default so I had to set those manually. But it worked perfectly other than that. Thanks.
Ben Shelock

related questions