To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flex and AIR

Reply
 
Thread Tools Display Modes
Old 10-23-2007, 12:45 PM   #1
blu3
Member
 
Join Date: Jun 2006
Location: Croatia
Posts: 84
Detecting browser window close event?

Is it possible to detect in Flex application browser window close event so that an action can be started when user closes Flex application, does anyone know how to do that if it's possible in the first place? The reason why i am asking this is because i have a multiuser Flex application where every user has it's own directory on a server side. Application has logout button which triggers cleanup of user's directory but what if the user just closes the window? I would like to be able to lunch that same cleanup upon browser close window.

thanks in advance

Last edited by blu3; 10-23-2007 at 12:58 PM.
blu3 is offline   Reply With Quote
Old 10-24-2007, 11:44 AM   #2
blu3
Member
 
Join Date: Jun 2006
Location: Croatia
Posts: 84
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

Last edited by blu3; 10-24-2007 at 11:47 AM.
blu3 is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flex and AIR

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:24 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.