How to communicate Flex with Html

In my flex application, whenever I closed the browser I want to execute an event. I am using
JBoss server. When I closed the browser I want to invalidate the session. Kindly help me to do this