Note that there are some explanatory texts on larger screens.

plurals
  1. POTo execute Flex cleanup function when browser is closed by user
    primarykey
    data
    text
    <p>I have a Flex client application. I need a clean up function to run in Flex when the user closes the browser. I found the following solution on the net, but it only works half-way for me. How could I fix it? <em>Thanks in advance for any responses!</em> <br/></p> <h2>Symptoms</h2> <ul> <li><code>CustomEvent</code> triggered, but not executed. <br/> >> EventHandler for <code>CustomEvent.SEND_EVENTS</code> is defined by a Mate EventMap. All the handler does is to call an <code>HTTPServiceInvoker</code>. In debug console, I'm able to see the handler and HTTPServiceInvoker being triggered, but neither the <code>resultHandlers</code> nor the <code>faultHandlers</code> were called. I know this event handler has no problem because when I dispatch the same <code>CustomEvent.SEND_EVENTS</code> in a button click handler, it behaves exactly as I expected) <li>Browser seems to wait for cleanUp function to complete before it closes. (all traces were printed before browser closes down) </ul> <h2>Code</h2> <p>I added the following into the index.template.html</p> <pre><code>window.onbeforeunload = clean_up; function clean_up() { var flex = document.${application} || window.${application}; flex.cleanUp(); } </code></pre> <p>And used the following in the application MXML file</p> <pre><code>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&lt;10000; i++){ trace(i); } } </code></pre> <h2>My Setup</h2> <ul> <li>FlexBuilder 3 <li>Mate MVC Framework (Mate_08_9.swc) <li>FlashPlayer 10 </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload