如何检查是否使用带有 swfobject 的 JavaScript 加载了 swf?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3939630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:45:37  来源:igfitidea点击:

How to check if a swf is loaded using JavaScript with swfobject?

javascriptswfobject

提问by Ruben Quinones

I have the following swf:

我有以下 swf:

    <head>
    # load js
    <script>
    function graph() {
     swfobject.embedSWF(
     "open-flash-chart.swf", "chart", "400", "180", "9.0.0", "expressInstall.swf",
     {"data-file":"{% url monitor-graph %}"});
        };
    </script></head>

<div id="chart"> </div>
<script>
graph();
</script>

I would like to call the graph function only if the swf has not been loaded yet, is there a way to do this? Thanks.

我只想在 swf 尚未加载时调用图形函数,有没有办法做到这一点?谢谢。

采纳答案by Jacob Relkin

The last argument to embedSWFis a callback function that is invoked when the swf has been embedded. It takes in an event object with a couple of properties denoting success/failure, etc. More on this at the swfobjectdocumentation.

最后一个参数embedSWF是一个回调函数,在嵌入 swf 时调用。它接受一个事件对象,该对象具有几个表示成功/失败等的属性。更多关于这方面的信息在swfobject文档

swfobject.embedSWF(
 "open-flash-chart.swf", "chart", "400", "180", "9.0.0", "expressInstall.swf",
 {"data-file":"{% url monitor-graph %}"}, {}, {}, 
   function(e) {
     if(e.success) graph();
   }
 );

回答by pipwerks

Use SWFObject to embed the SWF, then use the callback function to poll the SWF's PercentLoadedvalue.

使用 SWFObject 嵌入 SWF,然后使用回调函数轮询 SWF 的PercentLoaded值。

If the value is 0, the SWF has not loaded yet. When it hits 100, the SWF is fully loaded.

如果值为 0,则 SWF 尚未加载。当它达到 100 时,SWF 已满载。

Here's a tutorial for polling PercentLoaded, complete with code examples.

这是一个轮询教程PercentLoaded,包含代码示例。

回答by Sebastiaan Moeys

The swfobject callback only returns success if the DOM element was successfully created. It doesn't actually say anything about whether or not the SWF has loaded.

如果 DOM 元素已成功创建,swfobject 回调仅返回成功。它实际上并没有说明 SWF 是否已加载。

From the swfobject documentation:

从 swfobject 文档:

NOTE: success is report as true if the minimum Flash player required is available and that the Flash plugin-in DOM element for the SWF was created. SWFObject cannot detect if the swf file request has actually loaded or not.

注意:如果所需的最低 Flash 播放器可用并且为 SWF 创建了 Flash 插件 DOM 元素,则成功报告为真。SWFObject 无法检测 swf 文件请求是否已实际加载。