Before closing the html tab: how to notify Flex app internally?
Typically, you have no control over when the tab is closed and when the flash / flex app is destroyed. Therefore, you should not try to take any action on such an event, as they can be easily unloaded and your deinitialization logic will be broken.
In your case (closing connections), you should notice that all connections are automatically closed when the Flash Player application is destroyed.
Edit: There is actually a way to unload the 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 in a browser application), so you shouldn't completely rely on them anyway.
a source to share
You have to listen to the onbeforeunload event from the browser.
See more here http://seanmonahan.org/2009/03/19/preventing-users-from-accidently-navigating-away-from-your-flex-app/
a source to share