In this post we’ll see how to listen to the flash.events.Event.CLOSING event and prevent the window closing until the user’s interaction. That’s useful once you have some unsaved work in your application, so you can ask the user if he really wants to close the window before doing it.
Check out the code after the jump.
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" closing="closingHandler(event)"> <fx:Script> [CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; protected function closingHandler(event:Event):void { event.preventDefault(); Alert.show( "Do you really wanna close this window?", "Warning", Alert.YES|Alert.NO,null, alertCloseHandler ); } private function alertCloseHandler(event:CloseEvent):void { if(event.detail == Alert.YES) nativeWindow.close(); } ]]> fx:Script> s:WindowedApplication> |
Hope you enjoy it. See ya!




