Thursday, August 27, 2009

Move around a transparent AIR window

Some things are made out to be more complex than they have to be. If you want an Adobe AIR application without a standard window frame ("chrome" as they call it) then you have to manage allowing the user to move the window around yourself, as well as a way to close the app. It's harder to find a simple example than it should be.


// $background and $close can be any mouse-active
// display object on the stage, of course

// close the app on clicking a button
$close.addEventListener(MouseEvent.CLICK, closeApp);
function closeApp(ev:MouseEvent)
{
var myWindow:NativeWindow = this.stage.nativeWindow;
if (myWindow) myWindow.close();
}

// drag app around
$background.addEventListener(MouseEvent.MOUSE_DOWN, startMove);
function startMove(ev:MouseEvent)
{
var myWindow:NativeWindow = this.stage.nativeWindow;
if (myWindow) myWindow.startMove();
}


You can do a lot more than that, of course.

No comments: