4 Replies Latest reply on May 4, 2010 1:41 AM by Matt Le Fevre

    Confirmation of browser close event

    Calculoso

      Hello,

       

      In my application, I have a function "myCloseFunction" which looks something like this:

       

      public function myCloseFunction

      {

           Alert.show("This is an alert.");

           trace("myCloseFunction called");

      }

       

      This is only called upon closing the browser (set up using ExternalInterface.addCallback and window.onbeforeunload)

       

      The strange thing is, no alert ever pops up BUT the trace does show.  I have (of course) imported the alerts library (and used alerts elsewhere successfully in the application).  Has anyone ever experienced it or does anyone know of a fix?

       

      I will post my Javascript and .mxml file if needed, though I doubt it is.

       

      Thanks in advance for your help!

        • 1. Re: Confirmation of browser close event
          Flex harUI Adobe Employee

          I don't think you can block in Actionscript, and Alert doesn't block anyway.

          I don't think there is a way to use AS to interact during that event.

          • 2. Re: Confirmation of browser close event
            Calculoso Level 1

            Hmm, that is certainly useful information.  Is there anyway to do this in JS?  I

            assume that it is prevented do to potential abuses from developers P.O.V. in terms of spamming and other similar issues.

             

            Anyone have any ideas about handling browser close (y/n) choice from user?  It "should" be part of the browser ideally, but I'd like to put it in my application if necessary.

             

            Thanks for your help.

            • 3. Re: Confirmation of browser close event
              xingwen

              hi,

               

              Frastructed with the window close example using ExternalInterface.addCallback provided by Adove not working. Any help would truly appreciated.  here is what i've found:

              1. when tested, it passes data from html to Flex if I use onchange="callApp();" of the <Input> tag by typing something to invoke onchange event;

              2. if I choose to use window.onbeforeunload = callApp(); at the JavaScript section to detect window closing event, it does detect window is closing, but it won't pass the data ("Window Closing") to Flex. 

               

              Thank you very much for any help.

               

              In Html:

               

              <html><head>
              <title>wrapper/AddCallbackWrapper.html</title>
              <SCRIPT LANGUAGE="html/JavaScript">
                 
                 function callApp() {       
                      window.document.title = document.getElementById("newTitle").value;       
                      mySwf.myFlexFunction("Window Closing");

                  }
                 
                  //window.onbeforeunload = callApp();   
              </SCRIPT>
              </head>
              <body scroll='no'>

              <h1>AddCallback Wrapper</h1>

              Enter a new title: <input type="text" size="30" id="newTitle" onchange="callApp();">
              <table width='100%' height='100%' cellspacing='0' cellpadding='0'>
                  <tr>
                      <td valign='top'>
                          <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' height='200' width='400'>
                              <param name='src' value='testWrapper.swf'/>
                              <param name='flashVars' value=''/>
                              <embed name='mySwf' src='testWrapper.swf' pluginspage='http://www.adobe.com/go/getflashplayer' height='100%' width='100%' flashVars=''/>
                          </object>
                      </td>
                  </tr>
              </table></body></html>

               

              In Flex:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
                    <mx:Script>
                        <![CDATA[              
                        import flash.external.*;
                        import mx.rpc.events.ResultEvent;
                        import flash.events.Event;
                        import mx.rpc.events.FaultEvent;    
                        import mx.controls.Alert;
                       
                   public function initApp():void {
                      ExternalInterface.addCallback("myFlexFunction",myFunc);      
                   }

               

                   public function myFunc(s:String):void {           
                      Alert.show(s);    
                   }
                  ]]> 
                </mx:Script>
                     
                <mx:Label id="l1"/> 
              </mx:Application>