how can i detect swf close event in ActionScript 3. I need to perform some action while swf close event. is it 开发者_高级运维possible?
If you want to stop the application from closing you need to listen for the closing
and stop it (preventDefault
).
If you want to perform some shutdown actions when the application is closed then you register your actions on the close
event.
For AS3 , it would depend on how your application is closing.
If the user decided to close the browser window, you may have to look into Javascript for ways to intercept the event and prevent the window from closing. A little Googling should provide you with a few solutions, you'll only have to make sure it works with most browsers...
After you've managed that, you can call Actionscript within your JS function , using ExternalInterface, then return a call to JS from AS3, after you've done what you wanted , in order for the browser to close the window.
Now you still can give the user the choice to close the application directly from AS3 by implementing a "Close Application" button and informing the user it'd be kinda cool if she was using this button instead of simply closing the browser window, which then leads you to the situation where if she does, you won't need to call the JS function anymore, you may have to setup some Boolean so that functions don't get called twice!
精彩评论