How can I run code in Actionscript 3 when a page with my flash object is... well... I'm not sure of the term.
When the webpage is left and the flash applet is exited?
I don't think Flash has built-in functionality to catch this type of event. You might try a javascript solution. See this topic. By doing so, you could implement a flash object callback using Flash's ExternalInterface at the time the user leaves your page.