Flash player is notified in the browser to close or change the page (as3)

I need to detect my flash if the user closes their browser or goes to another page and the flash is not available. How do I achieve this?

+6
browser flash actionscript-3
source share
3 answers

ExternalInterfaceUtil.addExternalEventListener ("window.onunload", handleLogout, "unloadFlex");

package { import flash.external.ExternalInterface; public class ExternalInterfaceUtil { public static function addExternalEventListener( qualifiedEventName:String, callback:Function,callBackAlias:String ):void { // 1. Expose the callback function via the callBackAlias ExternalInterface.addCallback( callBackAlias, callback ); // 2. Build javascript to execute var jsExecuteCallBack:String = "document.getElementsByName('"+ExternalInterface.objectID+"')[0]."+callBackAlias+"()"; var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){"+jsExecuteCallBack+"};}"; // 3. Execute the composed javascript to perform the binding of the external event to the specified callBack function ExternalInterface.call( jsBindEvent ); } } } 

I don’t remember where I got it from, but I used it and it works very well. Of course, not all browsers will work together, but it's better than nothing ...

+15
source share

You can use a combination of Javascript and Flash to achieve what you are looking for.

Use Javascript to detect when a user navigates from a page. Use the javascript event to call into your Flash movie using ExternalInterface. After calling your code, you can process the event as needed.

+1
source share

The above worked fine for me with one exception: if I return null as my string, I don't want the message to pop up. It works for all browsers except IE, which brings up a dialog box that says "null".

This can be fixed by changing one line to add a null check:

 var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){if (" + jsExecuteCallBack + ") return "+jsExecuteCallBack+"};}"; 
+1
source share

All Articles