jQuery - 检测何时(flash)嵌入已准备好(可用)

时间:2011-10-08 16:20:31

标签: jquery flash javascript-events readystate

是否可以检测flash嵌入对象何时加载完整?是否有可以在所有浏览器中订阅该作品的活动?

谢谢, 韦斯利

1 个答案:

答案 0 :(得分:0)

不直接,但如果您通过ExternalInterface控制SWF,则很容易做到。首先,在SWF的flashvars中传递一个回调名称:

loadedCallback=swfLoadedCallback

此外,请确保SWF已将scriptAccess设置为sameDomainall

接下来,在页面中定义回调函数:

function swfLoadedCallback()
{
   // Note... if these were a real application, you would want 
   //    to use a setTimeout here to avoid Flash choking while 
   //    waiting for a response.
   alert('SWF loaded.  Do something.');
}

然后,在您的SWF中,添加如下代码:

import flash.external.ExternalInterface;
import flash.utils.setTimeout;

var params:Object = root.loaderInfo.parameters;
if (params && params.loadedCallback)
{
   // Set timeout to avoid syncronous issues
   setTimeout(function():void {
      if (ExternalInterface.available)
         ExternalInterface.call(params.loadedCallback);
   }, 1);
}