Performing the Flex Cleanup feature when a user closes a browser

I have a Flex client application. I need a cleanup function to run in Flex when the user closes the browser. I found the following solution on the net, but it only works halfway for me. How can i fix this? Thanks in advance for any answers!

Symptoms

  •  
  • CustomEventIt starts, but does not execute.
    → EventHandler for CustomEvent.SEND_EVENTSis defined by Mate EventMap. The entire handler is a call HTTPServiceInvoker. In the debug console, I can see that the handler and HTTPServiceInvoker are starting, but have not been called resultHandlers, nor faultHandlers. I know that this event handler has no problems, because when I send the same CustomEvent.SEND_EVENTSto the button click handler, it behaves exactly as I expected)  
  • The browser seems to be waiting for the cleanUp function to complete before it closes. (all traces were printed before closing the browser)

code

I added the following to index.template.html

window.onbeforeunload = clean_up;

function clean_up()
{
 var flex = document.${application} || window.${application};
 flex.cleanUp();
}

And used the following in an MXML application file

import flash.external.ExternalInterface;

public function init():void {
ExternalInterface.addCallback("cleanUp",cleanUp);
}

public function cleanUp():void {   

   var newEvent:CustomEvent = new CustomEvent(CustomEvent.SEND_EVENTS);
   newEvent.requestObj = myFormModel;

   dispatchEvent(newEvent);

   // for testing purposes
   // to see whether the browser waits for Flex cleanup to finish before closing down   
   var i:int;
   for (i=0; i<10000; i++){
        trace(i);
   }    

}

My setting

  •  
  • FlexBuilder 3  
  • Mate MVC Framework (Mate_08_9.swc)  
  • Flashplayer 10
+3
source share
3 answers

, , . result/fault HTTPService cleanUp. , onbeforeunload ( js clean_up). event.preventDefault() , . , preventDefault() ok/cancel:

?

OK, , , .

, . event.returnValue popop.

//tested only in Firefox
window.addEventListener("beforeunload", onUnload, false);
function onUnload(e)
{
   e.returnValue = "Some text that you want inserted between " +
     "'Are you sure' and 'Press OK' lines";
   e.preventDefault();
}
+2

100% . , " " . ( ), .

, , , . 5 , , 1 30 - , .

+1

An alternative way to clear a client-side session is to use JavaScript and external.interfaceclass in as3. Here is a sample code:

JavaScript:

function cleanUp()
{

    var process;
    var swfID="customRightClick";
    if(navigator.appName.indexOf("Microsoft") != -1){
        process = window[swfID];
        }else
    {
        process = document[swfID];
    }
    process.cleanUp();
}

and in the as3 class where the cleanup function is defined, use this:

import flash.external.ExternalInterface;

if (ExternalInterface.available)
{
    ExternalInterface.addCallback("cleanUp", cleanUp);
}

function cleanUp():void {// your code }
+1
source

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


All Articles