6 Replies Latest reply on Jun 22, 2011 7:19 AM by krishnamrajgoud

    Exit application in Flex 4

    som_che

      I am trying to close the browser on the click of a button. I tried NativeApplication.nativeApplication.exit but getting the error

      1120: Access of undefined property NativeApplication.

      and var exitingEvent: Event = new Event (Event.EXITING, false, true);

      is giving me error

      1119: Access of possibly undefined property EXITING through a reference with static type Class.

      can someone help to resolve this issue.

       

      Thanks

        • 1. Re: Exit application in Flex 4
          Cyril Hanquez Level 3

          NativeApplication is used for AIR app.

           

          use this instead:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
             
              <fx:Script>
                  <![CDATA[
                      private var browserType:String = "";
                      private var urlString:String;
                      private var request:URLRequest;
                     
                      private function closeWindow():void
                      {
                          /**
                           * For this to work in Firefox,
                           * Type in "about:config" in firefox address bar
                           * set dom.allow_scripts_to_close_windows to true.
                           */
                          urlString = "javascript:window.close();";
                          request = new URLRequest(urlString);
                          navigateToURL(request, "_self");   
                      }
                  ]]>
              </fx:Script>
             
              <mx:VBox>
                  <mx:Button label="Close Window" id="closeBtn" click="closeWindow()"/>
              </mx:VBox>

           

          </s:Application>

          • 2. Re: Exit application in Flex 4
            som_che Level 1

            Thank you for your response.

            Actually i already tried that option but the problem is, it shows a confirmation message before closing the browser and i dont want that.
            Any idea how we can supress it?

            • 3. Re: Exit application in Flex 4
              oldMster Level 3

              Nope, that is a browser security feature.  There are many things you just can't do from a browser, which is why AIR is available.

              Mark

              • 4. Re: Exit application in Flex 4
                Cyril Hanquez Level 3

                I confirm what oldMster is saying, you cannot force a browser window/tab to close (unless you created it in javascript), sorry.

                • 5. Re: Exit application in Flex 4
                  GamesByMike

                  I stumbled on this thread looking for a way to remove the confirmation popup. I was told that if we could reference the name of the window, we could close it without the popup. Any ideas on how to do this?

                  • 6. Re: Exit application in Flex 4
                    krishnamrajgoud Level 1

                    function ExitApp()

                    {

                      window.opener = null;

                      window.close();

                    }

                     

                    write this function in javascript(in html wrapper)

                     

                    call this function through ExternalInterface.call('ExitApp'); in you flex application (worked for me in IE6 does not give you a popup confirmation not sure about later version of browsers)