AIR widow/app drag, minimize, and close

In working on my Uploader tool, I had to do a bit of research on how to drag, minimize, and close an AIR app. Below is the summarized code in case anyone else is wondering how to do this.

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;

public class Main extends Sprite
{
	public function Main():void
	{
		// button events
		mc_exit.addEventListener(MouseEvent.CLICK, exitApp);
		mc_minimize.addEventListener(MouseEvent.CLICK, minimizeApp);
		mc_drag.addEventListener(MouseEvent.MOUSE_DOWN, dragApp);
	}

	private function exitApp(event:MouseEvent):void
	{
		NativeApplication.nativeApplication.activeWindow.close();
	}

	private function minimizeApp(event:MouseEvent):void
	{
		NativeApplication.nativeApplication.activeWindow.minimize();
	}

	private function dragApp(event:MouseEvent):void
	{
		NativeApplication.nativeApplication.activeWindow.startMove();
	}
}

Three buttons on the root of the flash file each with a listener that handles an action when the mouse is clicked on it. The drag button has to use ‘MOUSE_DOWN’ instead of ‘CLICK’ to work. NativeApplication is the AIR app and it looks to see which window is currently active to send the commands for.

Leave a Reply

Your email address will not be published. Required fields are marked *