Air 2.0 when closing the application, call preventDefault

Trying to prevent the application from closing when the button is pressed X, it still closes, but the AIR process is executed in the task manager. What is wrong with the code?

Application completed:

NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExiting);

Closing code:

private function onExiting(e:Event):void
{
e.preventDefault();
}
+3
source share
2 answers

Give it a try Event.CLOSING. This is what I use to cancel closing.

Event.EXITING occurs after removing the window and should be used only for cleaning, and not for closing the application.

From docs :

On Windows, the only time you get an output event after closing the last window (when autoExit = true).


An example of an "open" application:

<?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"
                       initialize="init()">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;

            private function init():void{
                this.addEventListener(Event.CLOSING, function(e:Event):void{
                    e.preventDefault();
                    Alert.show('Unclosable!');
                });
            }
        ]]>
    </fx:Script>
</s:WindowedApplication>

,
Alin

+4

, , . , false. , , true. . , true .

        private var boolExit:Boolean=false;

        private function alertClickHandler(event:CloseEvent):void{
            if(event.detail==Alert.YES){
                boolExit=true;
                NativeApplication.nativeApplication.exit();
            }

        }


        private function AppExit(e:Event):void{
            if(!boolExit)
                e.preventDefault();

            Alert.show("Do you want to exit application?",
                "Exit Confirmation",
                Alert.YES|Alert.NO,null,
                alertClickHandler
                );
        }

        public function init():void
        {
           . . . 
           this.addEventListener(Event.CLOSING,AppExit);
           . . .
        }
0

Source: https://habr.com/ru/post/1774472/


All Articles