Flex: How to Detect When the Browser Window Closes
I came across this thread post by blu3 on the FlashKit forums and thought it was too handy to not share on here.
I managed to pull this off and and here comes the solution. First i
declared cleanUp() function in Flex which does the dirty work and
cleans user's leftovers. Then i use ExternalInterface for registering
my cleanUp() function so that i can access it using JavaScript from
.html wrapper:Code:import flash.external.ExternalInterface;
ExternalInterface.addCallback("myFlexFunction",cleanUp);
public function cleanUp():void{//do the dirty work
........................
.........................}
Then i added following JavaScript function to my .html which embeds Flex application:
Code:<SCRIPT LANGUAGE="JavaScript">
window.onbeforeunload = clean_up;
function clean_up()
{var flex = document.${application} || window.${application};
flex.myFlexFunction();}
</SCRIPT>And that's it, works in both Firefox and IE when user either closes
browser window or goes to another web page. Alternative solution is
using FABridge or better yet proper session handling


Whoa
Glad you like it, best regards :)
blu3
Comment viewing options