Embedding Flash Objects for Internet Explorer

Since this was written, SWFobject2.0 has been released. Read "Embedding YouTube Videos the Standards Compliant Way—SFWobject 2.0" to learn more about using the updated version for embedding videos and other .swf files.

animation

Last week a colleague wrote to ask why she had to push a button to see her Web site and why it was loading so slowly. I took a look at the site, and had my usual reaction. "It looks fine in Firefox, let me check Internet Explorer."

When I checked in Explorer I saw just what she meant. Her site uses Flash, and due to a lawsuit between Microsoft and Eolas, Internet Explorer no longer processes <object>, <embed> or <applet> in the way that it used to. Now instead of using <object> to embed a Flash file, you need to use javascript in order for Internet Explorer users to load the content automatically. While this isn't a particularly new problem—it's been around for about a year—it's the kind of thing you might not notice unless you use Internet Explorer on a regular basis.

If you are currently using the old method to embed flash files, and you have Internet Explorer users who visit your site, you may want to consider using one of the new javascript methods. I've experimented with a few and found the SWFObject script to be the easiest to implement. If you have a better method, please share it in the comments section below.

Using SWFObject to embed Adobe Flash Content

While all the instructions and files you need are available on the SWFObject Web site, I thought it might be useful to give a quick overview of the process here.

  1. Download SWFObject 1.5, extract the files from the zip file and place swobject.js in your Web site directory.
  2. In Dreamweaver or your preferred editor, open the html file that includes your Flash content.
  3. Add <script type="text/javascript" src="swfobject.js"></script> within the head tags of your file, making sure to specify the correct path to swfobject.js
  4. Replace the code you are currently using to embed your Flash file with

    <div id="flashcontent">
    <img src="http://blog.case.edu/webdev/2007/04/19/active.jpg" width="180" height="300" alt="animation" /> </div>

    <script type="text/javascript">
    // <![CDATA[

    var so = new SWFObject("http://blog.case.edu/webdev/2007/04/19/active.swf", "sotester", "180", "300", "7", "#93a530");
    so.addVariable("flashVarText", "this is passed in via FlashVars for example only");
    so.addParam("scale", "noscale");
    so.write("flashcontent");

    // ]]>
    </script>


    The newly created <div> is used to hold the content that will be shown to users who don't have Flash enabled in their browser, while the script information tells the browser what file to get and what parameters to implement.
  5. Edit this content to specify the correct paths to your image and swf files, width and height of the elements, version of Flash you are using, etc. For illustrative purposes I've kept the above example fairly simple. It's the same code I'm using to embed the animation on this page. For your purposes you may want to include additional parameters.
  6. Upload your files and test in Internet Explorer and your usual browser.

That's pretty much it. To learn more about the process or to customize it for your particular needs visit the SWFObject Web site.

Activex Resources

Stumble This! Save to Delicious Share/BookmarkEmail This Post Email This Post

    Share on Google Buzz

10 Comments »
  1. M'colleague Andrew Harris has successfully used conditional comments and the tag to embed Flash movies, as in this page: http://www.unimelb.edu.au/dreamlarge/melbournemodel/arts_video.html Bonus: the code is valid XHTML 1.0 Transitional :-) We've found this method works well with Safari, Firefox and Internet Explorer.

    Comment by MLRuwoldt — April 25, 2007 @6:39 pm

  2. As someone who has used those codes that Microsoft is penalizing, I am grateful for this information. It sounds like a time-consuming remedy.

    Comment by Cool Marketing Products — April 27, 2007 @8:11 pm

  3. ML, Thanks for the tip on Andrew's method. It's nice to see another work around for this. It works great for I.E. 7, but it still seems to cause the problem on I.E. 6. Ah, well. There's probably a way to tweak that. p.s. Univ. of Melbourne looks like a beautiful campus.

    Comment by Heidi Cool — May 1, 2007 @1:24 pm

  4. That's why I am using Linux SUSE with Firefox, Opera, Seamonkey, Konqueror and so on. No problems with MIE. I think that simplicity is what we all need. Web sites which I created are simple, user-friendly and uses minimum "things" which could be replaced with other stuff (JavaScript for instance). Use pure XHTML + CSS and you won't face problems with Flash implementation. On the other hand, people who require Flash objects should find your post very useful.

    Comment by Jan from thrusites design — August 14, 2007 @6:28 am

  5. I am having problems implementing it in IE 6. Can someone suggest any tips?

    Comment by Girish — November 22, 2007 @1:10 pm

  6. Thank you for sharing. I really need this article. Is it work for IE 7?

    Comment by Kado Square — April 7, 2008 @8:01 pm

  7. Thank you for sharing. Really great article. Dous it work also for IE 7?

    Comment by Microsoft Word fan — June 1, 2008 @9:18 am

  8. I tried it in IE 7 and it is not working. My machine gets hung..

    Comment by India News — June 15, 2008 @2:26 am

  9. [...] embed an SWF file in a web page. According to Heidi, over at heidicool.com, “…due to a lawsuit between Microsoft and Eolas, Internet Explorer no longer processes <object>, <embed> or <applet> in the way [...]

    Pingback by Diaspar Was Not Always Thus — June 2, 2009 @8:53 pm

  10. [...] the Web using swfobject.js—in a manner similar to the method I described last year in "Embedding Flash Objects for Internet Explorer." You can also use this method for embedding regular Flash .swf files. Just substitute the [...]

    Pingback by » Embedding YouTube Videos the Standards Compliant Way—SFWobject 2.0 | Web Development Blog: Heidi Adams Cool — July 29, 2009 @12:07 am

Leave a comment

RSS feed for comments on this post. | TrackBack URL