Quit Event

Hello,
I have a big problem. I must port an application from browser enbedded .swf to projector .exe. All works fine untill the close event, which I had in the browser (thanks to IE’s onBeforeUnload(), but now in projector I cannot find another solution.
My question is: how can I tell that the projector window is trying to close, and how can I make sure some code is executed BEFORE it closes?

Thanks guys.