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);
var i:int;
for (i=0; i<10000; i++){
trace(i);
}
}
My setting
-
- FlexBuilder 3
- Mate MVC Framework (Mate_08_9.swc)
- Flashplayer 10
source
share