The Basics

SWFObject provides two different approaches to embedding a SWF: static publishing, which means the markup is added to the page manually, and dynamic publishing, which uses JavaScript to add the markup for you when your page loads in the browser.

Static publishing

Static publishing requires adding two <object> elements to your page as follows:

<object id="flashcontent"
         classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
         width="550px"
         height="400px">
  <param name="movie" value="mymovie.swf" />
 
  <!--[if !IE]>-->
  <object type="application/x-shockwave-flash" 
          data="mymovie.swf" 
          width="550px" 
          height="400px">
  <!--<![endif]-->
 
    <p>
      Fallback or 'alternate' content goes here.
      This content will only be visible if the SWF fails to load.
    </p>
 
  <!--[if !IE]>-->
  </object>
  <!--<![endif]-->
 
</object>

SWFObject's static publishing method also provides the option to 'register' the SWF with SWFObject. This enables additional functionality, including swfobject.getObjectById and Flash's Express Install feature. To register a SWF, simply add the following code to the <head> of your document:

<script type="text/javascript">
   swfobject.registerObject("flashcontent", "9", "/path/to/expressinstall.swf");   
</script>

Demo: static publishing

Visit the Static Publishing page for a more detailed overview of static publishing.

Dynamic publishing

Dynamic publishing requires adding one line of JavaScript in your document's <head>, and a 'target' element in your document's <body> (usually a <div>, but a <p> or any other block-level element should work).

<script type="text/javascript">
swfobject.embedSWF("mymovie.swf", "flashcontent", "550px", "400px", "9");
</script>
<body>
   <div id="flashcontent">
      Fallback or 'alternate' content goes here.
      This content will be replaced by the SWF
      after SWFObject embeds it.
   </div>
</body>

Demo: dynamic publishing

Visit the Dynamic Publishing page for a more detailed overview of dynamic publishing.

Questions or Comments?

If you have questions or would like to point out an error, please post your remarks in the SWFObject Google Group. Thanks!