Adobe 外部接口在 IE9 中不工作

发布于 2024-11-25 03:43:22 字数 2407 浏览 0 评论 0原文

我正在从 JavaScript 调用 Actionscript 函数,它适用于除 IE9 之外的所有浏览器。我将其范围缩小到检索电影对象的 js 函数:

<script type="text/javascript"> 
var swf;
... 

function flashReady() // This is called from ActionScript
{
    swf = getSWF("MyMovie");
    swf.MyExternalFunction(); 
}

function getSWF(movieName) 
{ 
    if (navigator.appName.indexOf("Microsoft") != -1) 
    { 
        return window[movieName]; 
    } 
    else 
    { 
        return document[movieName]; 
    } 
} 
... 
</script>

这是我的 HTML:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1" height="1" id="MyMovie">
    <param name="allowScriptAccess" value="always" />
    <param name="movie" value="/swf/movie.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffcc00" />
    <embed src="/swf/movie.swf" quality="high" bgcolor="#ffcc00" width="1" height="1" name="MyMovie" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

当我像这样调用外部函数时:

swf.MyExternalFunction(); 

在 IE9 中,我收到一个 JS 错误:

"Object doesn't support property or method 'MyExternalFunction'" 

显然 window[movieName],这对于 IE 来说很好,确实不能像以前那样在 IE9 中工作。 有什么建议吗?

:::UPDATE:::

这是迄今为止我的解决方案。它可能看起来不漂亮,但它有效:

var movie = false;

function initSWF(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        //alert("IE");
        if (typeof (window[movieName].MyExternalFunction) == 'function') {
            // alert("< IE9");
            movie = window[movieName];
        }
        else if (typeof (document[movieName].MyExternalFunction) == 'function') {
            // alert(">= IE9");
            movie = document[movieName];
        }
    }
    else {
        // alert("NON IE");
        movie = document[movieName];
    }

    return ((movie) ? true : false);
}

然后它的用法如下:

function flashReady() // This is called from ActionScript
{
    if(initSwf("MyMovie")) {
        movie.MyExternalFunction();
    } else {
        alert("Failed to initialize");
    }
}

I am calling an Actionscript function from JavaScript and it works in all browsers except for IE9. I narrowed it down to the js function that retrieves the movie object:

<script type="text/javascript"> 
var swf;
... 

function flashReady() // This is called from ActionScript
{
    swf = getSWF("MyMovie");
    swf.MyExternalFunction(); 
}

function getSWF(movieName) 
{ 
    if (navigator.appName.indexOf("Microsoft") != -1) 
    { 
        return window[movieName]; 
    } 
    else 
    { 
        return document[movieName]; 
    } 
} 
... 
</script>

Here is my HTML:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1" height="1" id="MyMovie">
    <param name="allowScriptAccess" value="always" />
    <param name="movie" value="/swf/movie.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffcc00" />
    <embed src="/swf/movie.swf" quality="high" bgcolor="#ffcc00" width="1" height="1" name="MyMovie" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

When I am calling the external function like this:

swf.MyExternalFunction(); 

In IE9 i get a JS error:

"Object doesn't support property or method 'MyExternalFunction'" 

Apparently window[movieName], which was good for IE, does not work in IE9 the way it used to.
Any suggestions?

:::UPDATE:::

Here is my solution so far. It may not look pretty, but it works:

var movie = false;

function initSWF(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        //alert("IE");
        if (typeof (window[movieName].MyExternalFunction) == 'function') {
            // alert("< IE9");
            movie = window[movieName];
        }
        else if (typeof (document[movieName].MyExternalFunction) == 'function') {
            // alert(">= IE9");
            movie = document[movieName];
        }
    }
    else {
        // alert("NON IE");
        movie = document[movieName];
    }

    return ((movie) ? true : false);
}

Then it is used like:

function flashReady() // This is called from ActionScript
{
    if(initSwf("MyMovie")) {
        movie.MyExternalFunction();
    } else {
        alert("Failed to initialize");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残龙傲雪 2024-12-02 03:43:22

我在 IE9 上也遇到过同样的问题,对我来说,这是 IE9 缓存 Flash 的情况。尝试清除浏览器缓存(F12 用于开发人员工具,并且有一个用于清除缓存的图标,或者我认为是 ctrl-R),然后再次尝试。

如果没有,请尝试通过将 JavaScript 对 ActionScript 的调用延迟 1 或 2 秒来进行调试,大致如下:

<SCRIPT LANGUAGE='Javascript'>

function delayForFlash() {
setTimeout("startFlash()", 1000);
}

function startFlash() {
getFlashMovie("flashdemo").restartFlash();
}

window.onload = function(){ delayForFlash();}
</SCRIPT>

这是为了给 Flash 提供足够的时间来加载所有内容。

I've had this exact same problem with IE9, for me, it was the case of IE9 caching the flash. Try clearing the browser cache (f12 for developer tools and there's an icon to clear the cache or ctrl-R i think), and then give it a shot again.

If that doesnt, try debugging by delaying your javascript call to actionscript by 1 or 2 seconds, something along the lines of this :

<SCRIPT LANGUAGE='Javascript'>

function delayForFlash() {
setTimeout("startFlash()", 1000);
}

function startFlash() {
getFlashMovie("flashdemo").restartFlash();
}

window.onload = function(){ delayForFlash();}
</SCRIPT>

This is to give enough time for your flash to load everything up.

梦途 2024-12-02 03:43:22

我也遇到过类似的问题,只是它在 IE9 中工作,而不是在 IE7/8 中工作。我相信我们两个问题的原因是相同的。我通过在列表上偶然发现这篇精彩文章解决了这个问题:Apart http://www.alistapart.com/ articles/flashsatay/

在文章之后,您的正确格式的 HTML 应为:

<object type="application/x-shockwave-flash" data="/swf/movie.swf" width="1" height="1" id="MyMovie">
    <param name="allowScriptAccess" value="always" />
    <param name="movie" value="/swf/movie.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffcc00" />
</object>

特别注意,我添加了 type 并删除了 标签。

据我所知,不再需要使用 标签。删除它意味着我们可以使用更简单的代码来触发我们的ExternalInterface函数:

// After the flash object has loaded...
var movie = document.getElementById('MyMovie');
if (typeof movie.MyExternalFunction === 'function') movie.MyExternalFunction();

我希望这会有所帮助。

I've been having similar trouble except that it was working in IE9 and not IE7/8. I believe the cause of both our problems are the same though. I solved it by stumbling across this wonderful article on A List: Apart http://www.alistapart.com/articles/flashsatay/

Following the article, your correctly formed HTML should read:

<object type="application/x-shockwave-flash" data="/swf/movie.swf" width="1" height="1" id="MyMovie">
    <param name="allowScriptAccess" value="always" />
    <param name="movie" value="/swf/movie.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffcc00" />
</object>

In particular notice that I've added a type and removed the <embed> tag.

As far as I can see, there is no need to use the <embed> tag any more. And removing it means we can use much simpler code to fire our ExternalInterface function:

// After the flash object has loaded...
var movie = document.getElementById('MyMovie');
if (typeof movie.MyExternalFunction === 'function') movie.MyExternalFunction();

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文