8 Replies Latest reply on Jul 30, 2010 3:01 PM by chris.campbell

    How to add exiting event listener in javascript

    jshrek Level 1

      I am trying to figure out how to add an event listener in javascript for the exiting event when the red x is clicked on a Windows window (top right corner).

       

      I found this among adobe documentation, but it does not work:

       

      var app = air.NativeApplication.nativeApplication;
      app.addEventListener(air.Event.EXITING, closeHandler);
      function closeHandler(event) {
        alert("Goodbye.");
      }

       

      And yes I have the AIRAliases.js included.

       

      Thanks

        • 1. Re: How to add exiting event listener in javascript
          Raul HUDEA Adobe Employee

          Hi,

           

          I think you are looking for air.Event.CLOSING which is dispatched immediately before the window is to be closed.

           

          nativeWindow.addEventListener(air.Event.CLOSING, function () {alert('CLOSING');}

           

           

          air.Event.EXITING is dispatched when the application exit sequence is started. On Windows, usually it is dispatched when you close the last opened window.

           

          Raul Hudea

          Adobe AIR Engineering

          1 person found this helpful
          • 2. Re: How to add exiting event listener in javascript
            jshrek Level 1

            The code posted above is from page 10 of the "HTML Developer’s Guide for ADOBE AIR (prerelease updated 11/16/2009)".

             

            I am actually exiting the program because I only have one window open and I click on the red x in the top right corner to shut it down... in theory, the example above provided by Adobe, should interrupt the exit sequence by displaying an alert box amd then shut the program down.


            Here's the excerpt from the manual...


            unload events (for body and frameset objects)
            Adobe AIR 1.0 and later


            In the top-level frameset or body tag of a window (including the main window of the application), do not use the unload event to respond to the window (or application) being closed. Instead, use exiting event of the NativeApplication object (to detect when an application is closing). Or use the closing event of the NativeWindow object (to detect when a window is closing). For example, the following JavaScript code displays a message ("Goodbye.") when the user closes the application:


            var app = air.NativeApplication.nativeApplication;
            app.addEventListener(air.Event.EXITING, closeHandler);
            function closeHandler(event)
            {
            alert("Goodbye.");
            }


            However, scripts can successfully respond to the unload event caused by navigation of a frame, iframe, or top-level window content.
            Note: These limitations may be removed in a future version of Adobe AIR.

            • 3. Re: How to add exiting event listener in javascript
              Raul HUDEA Adobe Employee

              Just tried the following application:

               

              <HTML>

              <head>

                  <script src="AIRAliases.js"></script>

                  <script>

                      var app = air.NativeApplication.nativeApplication;

                      app.addEventListener(air.Event.EXITING, closeHandler);

                      function closeHandler()

                      {

                              alert("Goodbye");

                      }

                  </script>

              </head>

              <BODY>

              </BODY>

              </HTML>

               

               

              And it works as expected in AIR 2 Beta2. Clicking the "X" on the current window, displays the alert and then exits the application (adl.exe process ends only after clicking OK on the alert dialog).

               

              Do you have a sample app that shows a different behavior ?

               

              Raul Hudea

              Adobe AIR Engineering

              • 4. Re: How to add exiting event listener in javascript
                jshrek Level 1

                I'm using AIR 1.5.3 ... let me try this simple example first and see if works and  I will report back shortly!

                • 5. Re: How to add exiting event listener in javascript
                  jshrek Level 1

                  Ok the simple example DOES work in 1.5.3 but I appear to have found that the problem lies with Introspector ...

                   

                  Add this line to code above:

                  <script type="text/javascript" src="includes/AIRIntrospector.js"></script>

                   

                  Then run the example using ADL from command line, and then hit F12 to open up Introspector window and then when you click red x to close the alert box does not pop up.

                   

                  Thanks

                  • 6. Re: How to add exiting event listener in javascript
                    Catalin Anastasoaie Adobe Employee

                    Thanks for reporting this issue. We have acknowledge your problem and opened an issue in our internal bug system (#2560616) in order to address it in a future version of AIR.

                     

                    We apologies for any inconvenience that came with it,

                    -Catalin

                    • 7. Re: How to add exiting event listener in javascript
                      kkm19 Level 1

                      is that fix? where can I found bug website? #2560616

                      thank you very much

                      • 8. Re: How to add exiting event listener in javascript
                        chris.campbell Adobe Employee

                        Unfortunately, this issue has not yet been fixed.  To help gage when this should be addressed do you mind telling us severe would you consider this bug?  Is it impacting your current project?

                         

                        Thanks,

                        Chris