Flash player notified on browser close or change page (as3)

后端 未结 3 1816
我在风中等你
我在风中等你 2020-12-15 13:20

I have to detect in my flash if the user closes his browser or goes to another page and the flash is not accessible anymore. How do i achieve that ?

相关标签:
3条回答
  • 2020-12-15 13:55

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

    That can be corrected by altering one line to add a null check:

    var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){if (" + jsExecuteCallBack + ") return "+jsExecuteCallBack+"};}";
    
    0 讨论(0)
  • 2020-12-15 14:04

    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 this from, but I've used it and it works pretty well. Of course not all browsers are going to cooperate, but it is better than nothing...

    0 讨论(0)
  • 2020-12-15 14:08

    You could use a combination of Javascript and Flash to achieve what you're looking for.

    Use Javascript to detect when the user navigates away from the page. Use the javascript event to call into your Flash movie using ExternalInterface. Once your code is called, you can handle the event as needed.

    0 讨论(0)
提交回复
热议问题