4

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.

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This is the correct and complete solution. Even if it is more than a year old, it should be marked as such.
Tried this but am getting a "Uncaught ReferenceError: e is not defined " error.
e is defined in the function like this var callbackfn = function(e) { if(e.success){} }.
0

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.

Comments

-6

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 Comments

down voted - it looks like this is not always true. Since yes, docs tells us that last param is load handler. But it won't return true if file not found. This is a quote from the link you've provided - NOTE: success is report as true if the minimum Flash player required is available and that the Flash plugin-in <object> DOM element for the SWF was created. SWFObject cannot detect if the swf file request has actually loaded or not.
This is a partial solution. pipwerks answer is the right onw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.