How to detect a window close event in an AIR application and how to prevent

My question is how can I prevent a user from closing the application? . I need a warning message to appear that asks the user if he really wants to leave the application. My application is developed in Adobe AIR . Please help, I'm in trouble.

+7
source share
1 answer

Yes, I had it too. But itโ€™s actually quite simple to intercept and prevent the closure.

Beware that this code will prevent the closing of the standard window! I do not recommend using it without adding a confirmation dialog or closing the code instead of a comment.

stage.nativeWindow.addEventListener(Event.CLOSING, onCloseCall); function onCloseCall(evt:Event):void { evt.preventDefault(); //Show dialogue here. } 

Now, how to show a warning message (aka dialog box) is completely up to your platform, method and needs. For example, if you use Flash Professional, a custom movie clip that you hide and show can do the trick. However, if you use Flex, there are ways to create a modal dialog. Learn it separately.

+11
source

All Articles