views:

193

answers:

4

While embedding a SWF in HTML is not too hard, there are a few subtleties for different browsers, detecting if Flash is installed, etc. For enabling AJAX, there are standard chunks of code you can use to save the hassle of coping with all cases... is their a similar 'reference implementation' to embed a SWF which covers all the bases?

+1  A: 

Apple (Link for example)

Content that your plug-ins will view needs to be embedded within HTML. Most browsers do this with an EMBED tag, but others require the OBJECT tag. For maximum compatibility, you can tune your page to support both.

Adobe (Link for example)

The OBJECT tag is used by Internet Explorer on Windows and the EMBED is used by Netscape Navigator (Macintosh and Windows) and Internet Explorer (Macintosh) to direct the browser to load the Macromedia Flash Player. Internet Explorer on Windows uses an ActiveX control to play Macromedia Flash content while all other browser and platform combinations use the Netscape plugin technology to play Macromedia Flash content. This explains the need for two tags.

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
       codebase="http://download.macromedia.com/pub/
                 shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
          WIDTH="550"
         HEIGHT="400"
             id="myMovieName">
    <PARAM NAME=movie VALUE="myFlashMovie.swf">
    <PARAM NAME=quality VALUE=high>
    <PARAM NAME=bgcolor VALUE=#FFFFFF>
    <EMBED href="/support/flash/ts/documents/myFlashMovie.swf"
        quality=high
        bgcolor=#FFFFFF
          WIDTH="550"
         HEIGHT="400"
           NAME="myMovieName"
          ALIGN=""
           TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"&gt;
    </EMBED>
</OBJECT>
Georg
+1  A: 

Many implementations of Flash embedding seem to be based on SWFObject. Is this the kind of thing you are looking for? Edit: project is hosted here now

fvu
+2  A: 

Is there a standard? Sadly no. The desirable points of a Flash embedding method are:

  1. modern browser compatible
  2. IE compatible
  3. ancient browser compatible
  4. standards-compliant
  5. supporting streamed Flash (play before the whole file is downloaded) in IE
  6. Don't Repeat Yourself
  7. allow fallback content
  8. no JavaScript reliance

but there is no one bunch of markup that satisfies all these points. Point 6 is impossible to achieve fully but some solutions fail worse than others.

About the simplest markup you can get away with is the version outlined in the classic Flash Satay article:

<object type="application/x-shockwave-flash" data="file.swf" width="x" height="y">
    <param name="movie" value="file.swf" />
    (Non-Flash content here)
</object>

The ALA article complains that this version won't prompt the user to download Flash if it isn't installed; personally I see this as a plus point. But it still fails on points 3 and 5. Point 5 may or may not matter: if your Flash file is a simple application, media player or loader stub it doesn't matter at all, but if it's a big animation it can be unfortunate.

Maybe point 3 doesn't matter any more; no-one's really using Netscape 4 or IE4 these days. But if it does to you, you need the old-school embed tag. This is also supported by modern browsers so that means you can use the ActiveX method for the outer object, so you get streaming in IE:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="x" height="y">
    <param name="movie" value="file.swf" />
    <embed type="application/x-shockwave-flash" src="file.swf" width="x" height="y" />
</object>

This is the ‘traditional’ method of embedding Flash. It fails on points 4 and 7 and is slightly worse on point 6.

The third approach, used by libraries such as SWFObject is to use JavaScript to choose the best way to instantiate Flash on the current browser. This can hit the all the above points except, naturally, 8. Some libraries offer ways to mitigate that by also including static object markup, trading point 8 for point 6.

bobince
A: 

I would recommend SWF Object compared to all the other options because it produces Standards Compliant html and is really easy to setup.

Paul Sheldrake