Run a script when the user closes the swf

Can you call a function when the user closes the browser window or navigates away from the page?

I’m making a cartoon, and I’m curious how long people watch it before closing the window or navigating away from the page. I could have it, every x seconds, report back the the server, and I can get a rough idea of how long they watched, but if it could report the exact time when the user closed it, I would know exactly.