ExternalInterface的页面刷新后不工作在IE

ExternalInterface的页面刷新后不工作在IE

本文介绍了ExternalInterface的页面刷新后不工作在IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况,IE在那里JS无法调用到Flash使用ExternalInterface的后,我点击刷新。我知道电影是越来越加载和code,做了 ExternalInterface.addCallback()似乎完成没有任何错误

下面是步骤破败重现:

  1. 开启IE浏览器并加载了电影的第一次,ExternalInterface的回调方法可用于JavaScript。
  2. 如果我打刷新,回调方法都无法使用,我得到的错误对象不支持此属性或方法
  3. 如果我清空缓存并刷新页面,他们可以再次使用。
  4. 如果我再砸再次刷新不清除我的缓存,它们是不可用的。
  5. 如果我关闭浏览器,然后重新打开,他们可以再次使用。

我碰到以前这种情况下,我pretty的确认所需的额外延迟下载和实例化SWF是什么让ExternalInterface的得到正确设置。我工作围绕这个问题的方法之前,是一个随机号码添加到SWF的URL的末尾,以便它永远不会从高速缓存使用,但是这不是一个真正的解决方案。

有谁知道如何解决这个问题?

编辑:

我应该提到的是,这种刷新后,ExternalInterface.available'是'真',而是'ExternalInterface.objectId'是'空'。

我已经试过随机化对象的值 ID 并嵌入名称和div容器的id在任何情况下, ExternalInterface.objectId 仍然


更多信息:

我看不出我插入了电影的方式会有所作为,但我想我会包括code只是要确定。我的电影是不是受点击激活的问题,我不想使用SWFObject的在这种情况下,由于Flash影片是一个备用的情况下HTML5音频不可用。

  VAR docContainer = document.createElement方法('格');
docContainer.innerHTML ='<对象
        +'的classid =CLSID:D27CDB6E-AE6D-11CF-96b8-444553540000'
        +'codeBase类=htt​​p://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0'
        +'的id =mp3player'
        +WIDTH =300'
        +高度=500>
    +'< PARAM NAME =allowScriptAccess的值=总是/>
    +'< PARAM NAME =电影值=mp3player.swf/>
    +'< PARAM NAME =质量值=高/>
    +'< PARAM NAME =BGCOLOR值=#FFFFFF/>
    +'<嵌入
        +'的src =mp3player.swf'
        +'品质=高
        +'BGCOLOR =#FFFFFF'
        +WIDTH =300'
        +高度=500'
        +',例如swLiveConnect =真
        +NAME =mp3player'
        +'的id =mp3player'
        +'的allowScriptAccess =永远
        +'类型=应用程序/ x-冲击波闪光
        +'PLUGINSPAGE =htt​​p://www.adobe.com/go/getflashplayer/>
    +'&所述; /对象>';
document.body.appendChild(docContainer);
 

解决方案

在情况下,你想知道为什么出现这种情况,至少在Internet Explorer中看来,Flash播放器加载为一个ActiveX控件,它是完全独立的DOM和JavaScript模块。当瑞士法郎被缓存,似乎ActiveX控件可以加载和运行之前,Javascript是准备接受的事件,从它。

这意味着,当Flash尝试使用ExternalInterface添加的回调,这将失败,因为JavaScript和DOM还没有被加载。

我通过等待第一个 ENTER_FRAME 事件,然后注册我的回调出现解决了这一问题。像这样的:

 保护功能registerExternalCallbacks(事件:事件):无效{

    removeEventListener(Event.ENTER_FRAME,registerExternalCallbacks);

    如果(ExternalInterface.available){
        ExternalInterface.addCallback(flash_play,播放);
        ExternalInterface.addCallback(flash_setVolume,setVolume);

        ExternalInterface.call(player_ready);
    }
}

//然后当瑞士法郎载荷,注册该事件的函数:
的addEventListener(Event.ENTER_FRAME,registerExternalCallbacks);
 

这将让玩家等到回调能够可靠地增加,然后调用称为JavaScript函数 player_ready 的信号,它已经可以使用。

I have a bizarre situation in IE where JS can't call up into flash using ExternalInterface after I hit "refresh". I know the movie is getting loaded and the code that does the ExternalInterface.addCallback() appears to be completing without any error

Here's a rundown of the steps to reproduce:

  1. Open IE and load up the movie for the first time, the ExternalInterface callback methods are available to JavaScript.
  2. If I hit refresh, the callback methods aren't available and I get the error Object doesn't support this property or method.
  3. If I clear my cache and refresh the page, they are available again.
  4. If I then hit refresh again without clearing my cache, they're unavailable.
  5. If I close the browser and reopen, they're available again.

I've run into this situation before and I'm pretty sure that the extra delay required to download and instantiate the swf is what's allowing ExternalInterface to get set up properly. The way I worked around this before was to add a random number to the end of the swf's url, so that it's never used from cache, but that's not a real solution.

Does anyone know how to solve this?

edit:

I should have mentioned as well that after refreshing, 'ExternalInterface.available' is 'true', but 'ExternalInterface.objectId' is 'null'.

I've tried randomizing the value of the object id and embed name and the id of the container div and in every case, ExternalInterface.objectId remains null.


More info:

I can't see how the way I'm inserting the movie would make a difference, but I thought I would include the code just to be sure. My movie is not affected by the "click to activate" issue and I don't want to use SWFObject in this case since the flash movie is a fallback in case HTML5 audio is not available.

var docContainer = document.createElement('div');
docContainer.innerHTML = '<object '
        + 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
        + 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" '
        + 'id="mp3player" '
        + 'width="300" '
        + 'height="500">'
    + '<param name="allowScriptAccess" value="always" />'
    + '<param name="movie" value="mp3player.swf" />'
    + '<param name="quality" value="high" />'
    + '<param name="bgcolor" value="#ffffff" />'
    + '<embed '
        +'src="mp3player.swf" '
        + 'quality="high" '
        + 'bgcolor="#ffffff" '
        + 'width="300" '
        + 'height="500" '
        + 'swLiveConnect="true" '
        + 'name="mp3player" '
        + 'id="mp3player" '
        + 'allowScriptAccess="always" '
        + 'type="application/x-shockwave-flash" '
        + 'pluginspage="http://www.adobe.com/go/getflashplayer" />'
    + '</object>';
document.body.appendChild(docContainer);
解决方案

In case anyone is wondering WHY this happens, at least for Internet Explorer it seems that the Flash player is loaded as an ActiveX control, which is completely seperate from the DOM and JavaScript modules. When the .swf is cached, it seems that the ActiveX control can load and run it before Javascript is ready to accept events from it.

This means that when Flash tries to use the ExternalInterface to add the callbacks, it will fail because the JavaScript and the DOM have not been loaded.

I fixed the problem by waiting for the first ENTER_FRAME event, and then registering my callbacks there. Like this:

protected function registerExternalCallbacks(event:Event):void {

    removeEventListener(Event.ENTER_FRAME, registerExternalCallbacks);

    if (ExternalInterface.available) {
        ExternalInterface.addCallback("flash_play", play);
        ExternalInterface.addCallback("flash_setVolume", setVolume);

        ExternalInterface.call("player_ready");
    }
}

// and then when the .swf loads, register the function on the event:
addEventListener(Event.ENTER_FRAME, registerExternalCallbacks);

This will make the player wait until the callbacks can be added reliably, and then calls a javascript function called player_ready to signal that it is ready to be used.

这篇关于ExternalInterface的页面刷新后不工作在IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:57