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

妖精的绣舞 提交于 2019-11-28 05:30:47

问题


I have the following 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.


回答1:


The last argument to embedSWF is 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 swfobject documentation.

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();
   }
 );



回答2:


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

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

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




回答3:


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.

From the swfobject documentation:

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.



来源:https://stackoverflow.com/questions/3939630/how-to-check-if-a-swf-is-loaded-using-javascript-with-swfobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!