Reputation: 57974
I am trying to center a launched window in flex, there is a NativeWindow.x and NativeWindow.y but flex uses the Window class which does not have these properties, so does anyone know how to center a window? Thanks!!
Upvotes: 2
Views: 4715
Reputation: 21
This is what I use
nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
Seems to work well
Upvotes: 2
Reputation: 25
actually this works better in flex 4.5 and above
nativeWindow.x = (Screen.mainScreen.bounds.width - nativeWindow.width)/2;
nativeWindow.y = (Screen.mainScreen.bounds.height - nativeWindow.height)/2;
Upvotes: 0
Reputation: 41
isn't this better?
example docs:
// center the window on the screen
var screenBounds:Rectangle = Screen.mainScreen.bounds;
nativeWindow.x = (screenBounds.width - nativeWindow.width) / 2;
nativeWindow.y = (screenBounds.height - nativeWindow.height) / 2;
from livedocs: about window containers ¨
both solutions worked for me even on multiple screen system (Win7)
Upvotes: 1
Reputation: 57974
I figured it out:
window.nativeWindow.x = (Screen.mainScreen.bounds.width - window.width)/2;
window.nativeWindow.y = (Screen.mainScreen.bounds.height - window.height)/2;
I think you have to call this AFTER window.open() though.
Upvotes: 3