• flickr
  • linkedin
  • twitter
  • rss
Stopping an AIR app window closing with Flash IDE AS3

Stopping an AIR app window closing with Flash IDE AS3

If you’re doing document manipulation or something you might need to confirm with the user of the app that they want to quit the app before letting them quit.

To do this, there’s plenty of help online if using Flex, but if writing AIR using the Flash IDE, it’s slightly different.

1. Import the NativeWindow and NativeApplication classes.

import flash.display.NativeWindow;
import flash.desktop.NativeApplication;

2. Set your window instance.

public var window:NativeWindow; 

3. set the window instance – this is a reference to the desktop window the AIR app is in.

window = this.stage.nativeWindow; 

4. Add an Event.CLOSING listener to the window instance.

window.addEventListener(Event.CLOSING, exitingHandler);

5. In the handler for that event, go ‘e.preventDefault()’ to stop the window closing. After that point, you need to manually call NativeApplication.nativeApplication.exit(); to exit the module.

/// runs when the app is being closed
private function exitingHandler(e:Event):void 
Utils.confirm("Are you sure you want to exit?", closeHandler);

/// closes the app.
private function closeHandler():void


AIR is awesome.

Tech Reference: ,

Larry's a 30-something chap interested in travel, being a dork and changing the world via less boring training.

Leave a reply