views:

42

answers:

1

I am going to be loading a swf into a div tag when the user initiates some action. The div tag's id is container, the embedded swf's tag id will be swf_content. I want to be able to set a variable to that swf_content tag when it is loaded. So something like:

$("#swf_content").ready(function() {
    SWF = $("#swf_content").get(0);
})

What is the best way to do this, assuming it won't be loaded until some arbitrary user action?

A: 

The simplest way is to use SWFObject, see dynamic embedding section.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
      <head>
        <title>SWFObject dynamic embed - step 3</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="swfobject.js"></script>

        <script type="text/javascript">
        swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
        </script>

      </head>
      <body>
        <div id="myContent">
          <p>Alternative content</p>
        </div>
      </body>
    </html>
Shein Alexey
I know how to use swfobject :p, I'm looking at how to know when an object was added to the DOM.
viatropos
Again, see doc for embedSWF here, http://code.google.com/p/swfobject/wiki/api, last param is callback function that fired on successful or failed swf embedding, see also an example here http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test_dynamic2.html
Shein Alexey