views:

37

answers:

1

Hi all, I know there have been other questions on getting JavaScript / Flex ExternalInterface to play nicely, but I've what I think is a weird one. It works perfectly in every browser except Safari (on a Mac). Chrome, IE, Firefox - all ok, but Safari, nope it just wont fire. I've copied my code below, can anyone see why it doesn't work in Safari pls ?

(the 'are you sure' dialog window appears in Safari but the method in the Flex app just doesn't get called)

Cheers Alex

Flex code :

        if(ExternalInterface.available){
          ExternalInterface.addCallback("flexShutdownHandler",flexShutdownHandler);
          fnMyLogger("External interface available - setting shutdownhook");
        }else{
          fnMyLogger("External interface *NOT* available");
        }

        private function flexShutdownHandler():void{
            fnMyLogger("*****************");
            fnMyLogger("** Logging out **");
            fnMyLogger("*****************");
            // other code as well here where I 
            //   can tell doesn't get called ....


        }

JavaScript code :

    <script language="JavaScript" type="text/javascript">
        function thisFlexApp(flexName) {
            if (navigator.appName.indexOf("Microsoft") != -1 || navigator.appName.indexOf("MSIE") != -1) {
                return window[flexName];
            } else {
                return document.getElementById(flexName);
            }
        }

        function shutdownHook(){
            window.alert ("are you sure ?");
            thisFlexApp("MyFlexApp").flexShutdownHandler();
        }
        //Set up notification for flex app when page unloads
        window.onbeforeunload = shutdownHook;

    </script>
A: 

Hi Alex,

usually, when errors occur in ExternalInterface the problem is not the code you have shown but the embedding code of the SWF.

as a first step, I would recommend you to embed you SWF's with SWFObject inside the HTML page, this usually will fix the Safari Mac issue.

Avi Tzurel