You need javascript to protect from leaving the current page where your flash is located. If user really wants to leave the page then make your http call, else just stay inside the page.
Here are some links... that should help:
How to logout during onbeforeunload/onunload using Javascript
To execute Flex cleanup function when browser is closed by user