Adobe AIR: how to make things upon closing the application

Sometimes we need to catch the closing of our AIR application to make some things like storing the window's position and size. We can do that in our code.

What we need is to add a listener to our nativeWindow.

stage.nativeWindow.addEventListener(Event.CLOSING, onNativeWindowClosing);

and then to prevent the closing of the application till we do what we want:

private function onNativeWindowClosing(e:Event):void {		// prevent the closing of the application	e.preventDefault();		// ...	// do some things here	// ...		// close the application	NativeApplication.nativeApplication.exit();	}
If you enjoy this post, share it on Twitter, Facebook or LinkedIn.

With over two decades of deep front-end expertise, I offer comprehensive web consultancy and stack audits, alongside specialized workshops, training, and engaging public speaking to elevate your team's skills and optimize your digital presence. Contact me.