ExternalInterface.addCallback not working in IE8 Flash 10.0 or below
Asked Answered
E

0

1

I have a small flash app that I load dynamically upon jQuery document.ready. It works in all browsers except for IE. When the installed version of FlashPlayer is less than 10.1, the callbacks added via addCallBack are not present. I've compiled the app with the mxmlc in flex 3.5 which the target player is 9.0.124 so it should work. I've built other larger flex apps and had no problems with ExternalInterface and IE. The app loads and the ExternalInterface.call method fires and IE responds, but the callbacks just aren't there. No errors are being thrown.

MyApp.as

public class MyApp extends Sprite {
    private var sounds:Dictionary = new Dictionary();
    private var channel:SoundChannel = new SoundChannel();
    private var onLoadHandler:String;

    public function MyApp() {
        flash.system.Security.allowDomain("*");

        var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
        onLoadHandler = flashvars.onLoad;

        addEventListener(Event.ENTER_FRAME, registerExternalCallbacks);
     }

    private function registerExternalCallbacks(event:Event):void{
        removeEventListener(Event.ENTER_FRAME, registerExternalCallbacks);

        if (ExternalInterface.available) {
            ExternalInterface.addCallback("addSound", addSound);
            ExternalInterface.addCallback("playSound", playSound);
            ExternalInterface.addCallback("getCameraCount", getCameraCount);

            if (onLoadHandler) {
                ExternalInterface.call(onLoadHandler);
            }
        }
    };

    private function addSound(name:String, url:String):void{
        var sound:Sound = new Sound();
        sound.load(new URLRequest(url));
        sounds[name] = sound;
    }

    private function playSound(name:String):void{
        if (sounds[name] != null) {
             channel = sounds[name].play();
        }
    }

    private function getCameraCount():int {
        return Camera.names.length;
    }
}

HTML markup

<object width="1" height="1" id="MyApp" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" style="position: absolute; top: -999px; left: -999px;">
    <param value="MyApp.swf" name="movie">
    <param value="always" name="allowScriptAccess">
    <param value="false" name="allowFullScreen">
    <param value="false" name="loop">
    <param value="false" name="menu">
    <param value="high" name="quality">
    <param value="onLoad=onLoad" name="flashvars">
    <embed width="1" height="1" flashvars="onLoad=onLoad" quality="high" menu="false" loop="false" allowfullscreen="false" allowscriptaccess="always" name="MyApp" src="MyApp.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" type="application/x-shockwave-flash">
</object>

Ideally, I wouldn't be too worried, but my boss would like this to work for older flash versions so our customers are forced to update.

Enliven answered 6/3, 2013 at 14:3 Comment(5)
Unfortunately can't test, but I remember doing ExternalInterface communication about 5 years ago on flash player 9 on OSX and Windows with Firefox and IE(probably 8, not sure). Long story short, I remember a couple of 'gotchas' like using the same object id and embed name as IE uses the activeX FP plugin which is different from the Firefox plugin. The other 'gotcha' was allowScriptAccess which should be set to always. Your markup looks ok, but you might want to change allowscriptaccess to allowScriptAccess in your embed tag, maybe that will fix it.Gallinule
Also, I recommend using swfobject which is nicer/easier to use/prettier to look at :)Gallinule
@GeorgeProfenza I had previously tried altering case of allowScriptAccess, but had no affect. As for swfobject, I looked at it, but saw no real value over my implementationEnliven
When I did ExternalInterface stuff using swfobject it always worked, as opposed to when I had to keep track of tag attributes myself. My suggestion is give swfobject a try with IE8 and FP9, hopefully it solves your problemGallinule
+1 on using SWFObject, it can really help with cross browser issuesHydrocephalus

© 2022 - 2024 — McMap. All rights reserved.