Actionscript 3 获取与swf对象一起工作的外部接口,can';我不明白我是什么';我做错了

Actionscript 3 获取与swf对象一起工作的外部接口,can';我不明白我是什么';我做错了,actionscript-3,swfobject,externalinterface,Actionscript 3,Swfobject,Externalinterface,我正在使用swf对象嵌入swf。我试图使用外部接口从JS调用flash函数,但遇到了问题。我搜索了所有的文件,读了很多东西,我确信我做得对。有人能指出问题出在哪里吗 var flashvars = {}; var params = {wmode:"opaque", allowscriptaccess:"always" }; var attributes = {id:"MySwf", name:"MySwf"}; swfobje

我正在使用swf对象嵌入swf。我试图使用外部接口从JS调用flash函数,但遇到了问题。我搜索了所有的文件,读了很多东西,我确信我做得对。有人能指出问题出在哪里吗

        var flashvars = {}; 
        var params = {wmode:"opaque", allowscriptaccess:"always" }; 
        var attributes = {id:"MySwf",  name:"MySwf"};
        swfobject.embedSWF("MySwf.swf", "flashContent", "600", "400", "9.0.0", "swfs/expressInstall.swf", flashvars, params, attributes,function(e){
            if(e.success){
                _flashRef = e.ref;
                testExternalInterface();                    
            }else{
                alert("We are sorry, flash is required to view this content.");
            }
        });
       function testExternalInterface(){        
              var swf = document.getElementById("MySwf");
              swf.sendMeTheGoods("TEST TEST");
    };
以上是我的flash中的嵌入代码和js函数

        if (ExternalInterface.available)
        {
            trace("adding external interface");
            ExternalInterface.addCallback("sendMeTheGoods", sendMeTheGoods);
        }
    public function sendMeTheGoods(text:String):void
    {
        trace("setting vars")
        trace(text);
        txtYouSent.text = text;
    }
我得到了未捕获的错误TypeError:Object#没有方法'sendMeTheGoods'


我尝试了引用document.getElementById(“MySwf”);和document.getElementById(“flashContent”);我从两个方面都得到了错误。有什么建议吗?

var swf=navigator.appName.indexOf(“Microsoft”)!=-1.窗口[“MySwf”]:文档[“MySwf”]

外部接口API不是立即可用的,需要一秒钟才能准备好。您的回调可能发生在Flash Player初始化EI API之前。尝试在回调中添加延迟,延迟“test”函数的调用

好奇的是,在回调函数中,事件参数
e
引用了Flash对象,这有用吗?事件还有一个
id
属性,您可以检查该属性以确认正确的id是什么。最后,您似乎指定了两个不同的id:一个在
属性
对象中,另一个在
swfobject.embedSWF()
的第二个参数中。谢谢,这是真的,我修复了它,但我仍然有相同的问题,就是文档。getElementById(“MySwf”);这有缺陷吗?为什么使用document[MySwf]而不是document.getElementById(“MySwf”);