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

Ruben Quinones picture Ruben Quinones · Oct 15, 2010 · Viewed 13.7k times · Source

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.

Answer

pipwerks picture pipwerks · Apr 18, 2013

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.