Tagged with

air

Setting a spark Window x and y on screen

I am starting to do a lot more AIR development and found something that baffled me a bit the other day. I am creating new Windows in my AIR app and I wanted to create the window and then have it open on screen where I would like. An example of this is I have a window that acts like a menu for my app so I wanted the window I create to open at 4px on the Y and 25px on the Y.

 
You would think it would be a easy as doing the following:
 
 
var mywindow:Window = new Window();
mywindow.x = 4;
mywindow.y = 25;
mywindow.open();
 
However this does not work as you would expect. This was a bit lame if you as me and the answer was not obvious unless you have doen a lot of AIR development and know what I am about to say. You have to listen for the window open to complete and then call the move() function and pass it the x and y for this to work. 
 
Checkout the following code:
protected function creationCompleteHandler(event:FlexEvent):void
{

var mywindow:Window = new Window();
 
mywindow.addElement( workingSets );
mywindow.width = 115;
mywindow.height =200;
mywindow.maximizable = false;
mywindow.resizable = false;
mywindow.addEventListener(AIREvent.WINDOW_COMPLETE, onWindowComplete);
.open();
}
 
private function onWindowComplete(event:AIREvent):void
{
event.currentTarget.move(4,25);
}