AIR – move, minimize and close application
April 23rd, 2009
Hi again folks, today working with AIR application i was searching something about control the window and database using Flash CS4, but today i will talk about only window control, close, minimize and move application window, its so simple do it, basically you need import only NativeApplication class, see the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package { import flash.desktop.NativeApplication; import flash.display.MovieClip; import flash.events.MouseEvent; public class DocumentClass extends MovieClip { public var closeBt :MovieClip; public var minBt :MovieClip; public var recordBox :MovieClip; public function DocumentClass():void { closeBt.addEventListener(MouseEvent.CLICK, closeApp); minBt.addEventListener(MouseEvent.CLICK, minApp); recordBox.addEventListener(MouseEvent.MOUSE_DOWN, dragApp); } } } |
We have now three functions: closeApp, minApp and dragApp. Three simple steps to take the window control, lets start with dragApp, the function that will drag your AIR Application using MOUSE_DOWN event.
Now we need put this private function inside the document class, bellow the code:
20 21 22 23 | private function dragApp(m:MouseEvent):void { stage.nativeWindow.startMove(); } |
The function will work only when mouse is down in the recordBox Movieclip, now you can drag your application using mouse moviment. Now to close and minimize the application you will use a simple CLICK event.
25 26 27 28 29 30 31 32 33 | private function closeApp(m:MouseEvent):void { NativeApplication.nativeApplication.exit(); } private function minApp(m:MouseEvent):void { stage.nativeWindow.minimize(); } |
To close the application using Flash CS4 you need use the NativeApplication and not only NativeWindow. But is so easy to use and now you can create your AIR application using a custom chrome. Try it!





October 2nd, 2009 at 09:57
Thanks this is really useful.
October 12th, 2009 at 12:37
This was wonderful! Thank you very much.
May 16th, 2010 at 11:43
Finally it is very nice to pick up someone who knows what he or she
is bloggin about! Man, a million thanks, i “scanned” a lot about that theme, but your blog post is fully right! %URL% is saved in bookmarks, Feed is subscribed!