2010-04-15 108 views
0

我正在使用以下代码。它使用getElementByID可以正常工作,但如果使用OS检测功能,它将停止工作。Flash/Javascript通信错误

function getFlashMovie(movieName) 
{ 
    var isIE = navigator.appName.indexOf("Microsoft") != -1; 
    return (isIE) ? window[movieName] : document[movieName]; 
} 

getFlashMovie('myId').sendToActionsript(str); 

上面的代码不起作用,而下面的代码行是任何想法?

document.getElementById('myId').sendToActionscript(str); 

编辑:另一块代码为同样的事情,这是不工作。

 function getFlashMovieSecond(movieName) 
     { 
        if (window.document[movieName]) 
        { 
         return window.document[movieName]; 
        } 
        if (navigator.appName.indexOf("Microsoft Internet")==-1) 
        { 
         if (document.embeds && document.embeds[movieName]) 
          return document.embeds[movieName]; 
        } 
        else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) 
        { 
         return document.getElementById(movieName); 
        } 

     } 
+2

尝试使用自带的帮助(例子http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external /ExternalInterface.html#includeExamplesSummary) - 逐渐剥离不需要的位,并将代码合并到项目中。需要记住的是,有些浏览器使用嵌入标签获取Flash内容,而其他浏览器则使用object标签,因此请确保在两个标签上都有相同的名称/标识,并且AllowScriptAccess也设置为“始终”。 HTH – 2010-04-15 14:06:10

回答

0

这似乎是工作

function thisMovie(movieName) { 

    if (navigator.appName.indexOf("Microsoft") != -1) { 

        return window[movieName]; 

    } else { 

        return document[movieName]; 

    } 

}