views:

92

answers:

1

I am building an air app in Flex 4. I am creating windows as I need them in a chromeless application.

Here is what I have in my main app creation complete

protected function creationCompleteHandler(event:FlexEvent):void
            {

                facade.sendNotification(AppFacade.APP_INIT, this);
                var buttons:NavigatorWindow = new NavigatorWindow();
                var workingSets:WorkingSets = new WorkingSets();
                buttons.addElement( workingSets );
                buttons.width = 115;
                buttons.height =200;
                buttons.maximizable = false;
                buttons.resizable = false;

                buttons.addEventListener(AIREvent.WINDOW_COMPLETE, onWindowComplete);
                buttons.open();


            }

            private function onWindowComplete(event:AIREvent):void
            {
                event.currentTarget.x = 100;
                event.currentTarget.y = 100;
            }

for some reason the application adds the window in the middle of the screen and if I set the x and y of the Window it does not put it where I expect in the upper left of my screen. How do I position the window where I would like when it is opened?

thanks,

A: 

The spark.components.Window exists inside a NativeWindow you'll need to position the NativeWindow if you want to move it around on the screen. It is a bit confusing because you can position the Window inside the native window as well. You'll have to do the positioning after creation complete, otherwise you'll get null reference errors.

You could invoke the window like this if you created a component based on spark.components.Window:

var win:MyWindow = new MyWindow();  //MXML component
win.height = 150;
win.width = 300;
win.systemChrome = NativeWindowSystemChrome.NONE;
win.type = NativeWindowType.LIGHTWEIGHT;
win.showStatusBar = false;
win.transparent = true;
win.alwaysInFront = true;
win.open(true);

Then in that mxml component, you set an creationComplete event handler to do this:

var padding:int = 25;
this.nativeWindow.x = Screen.mainScreen.visibleBounds.right - this.width - padding;
this.nativeWindow.y = Screen.mainScreen.visibleBounds.top + padding;

This should put your new window in the top right hand corner with 25px of padding on the top and right.

bwizzy
Actually I figured out you have to call move() on the window. http://mswallace.com/2010/06/24/setting-a-spark-window-x-and-y-on-screen/
mswallace

related questions