tags:

views:

272

answers:

2

I've say almost everything in the title : In firefox (or IE or whatever), when the tab is closed, I remember you could be notified of this, and I'd like to notify my Flex app and tell it to close (whenever it's possible) all the connexions that are opened.

Does anybody know the way to do this ? Thank you !

A: 

Generally you have no control over when tab is closed and when flash/flex application is destroyed. So you should not attempt to take any actions on such event, since they may be easily preempted and your deinitialization logic would be disrupted.

In your case (closing connections) you should note that all connections are closed automatically upon application destruction by Flash Player.


Edit: Actually there is a way to catch page unload event in some cases (see the other answer). But there is no guarantee that such methods will always work (i.e. they may not work on browser application close), therefore you still should not completely rely on them.

dragonfly
With gmail : try to create a new mail.Type a few words in the body,then try to close the tab : you'll get a message asking if you want to save the draft (something like that).Thus I thought it could be possible to know when the tab was closed, and just tell the SWF application that it had to close all the opened connexions. I don't know if there's an event that is sent to the objects of the SWF file before destruction.Thanks for your answer !
Olivier Pons
+2  A: 

You have to listen to the onbeforeunload event from the browser.

See here for more details : http://seanmonahan.org/2009/03/19/preventing-users-from-accidently-navigating-away-from-your-flex-app/

PeZ
Unfortunately this will not help if user just closes the browser, but thanks for useful link.
dragonfly