Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the ultimate way to embed Flash (swf) files to HTML (and XHTML) documents?

Like most people I use SWFObject to embed Flash (swf) files to my Web projects.

As you know SWFObject offers 2 ways to embed Flash: Static publishing and Dynamic publishing.

Static publishing uses regular markup to embed the file to the document and also do checks with JavaScript that you can't make with regular markup alone. This is good as if you have customers that can't have JavaScript turned on (search engines, some portable devices...), the file will still show up (if they have the correct Flash plug-in installed). But if you have people on legacy/unpatched Internet Explorer (between April 2006 and April 2008) they will have the dreaded "click to activate" to interact with the Flash.

Dynamic publishing uses JavaScript to embed the Flash. This will get rid of the "click to activate" feature on old IE but if JavaScript is off the Flash will not be there at all.

Both methods have its advantages and inconvenients. In an utopic world we would all use the dynamic publishing method, but we (or at least some of us like me) are stuck with customers using really old systems with IE 6 (they would like to upgrade but they can't because of badly designed software that would cost 10K+$ to upgrade). I need to support legacy IE and want to get rid of the "click to activate" feature while supporting people with JavaScript off.

What about combining static and dynamic publishing methods? What about something like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>SWFObject 2 static+dynamic publishing example page</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("test.swf", "myContent", "300", "120", "9.0.0", "expressInstall.swf");
        </script>
    </head>
    <body>
        <div id="myContent">
            <object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" height="120">
                <param name="movie" value="test.swf" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="test.swf" width="300" height="120">
                <!--<![endif]-->
                <div>
                    <h1>Alternative content</h1>
                    <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                </div>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
    </body>
</html>

I showed that to an integrator and he told me I should use <object> and <embed> tags...

What would be the ultimate way to embed Flash to Web projects? A solution that:

  • Will work with JavaScript off (Flash embedded in alternate content)
  • Will pass the W3C validator
  • Will remove the "click to activate" on legacy/unpatched IE
  • Will use the Flash detection/auto-install of SWFObject

EDIT: Added bounty. Please, I don't want to see answers like "don't bother no one have JavaScript off nowdays" or "if javascript is off most likely Flash will be off too".


EDIT 2: The answer I'm looking for is the best way to embed Flash statically (with regular HTML tags). Over that, I will add dynamic publishing. Something like this that will work in all major browsers since IE 6 and that will pass W3C validation.


like image 266
AlexV Avatar asked Jul 07 '10 13:07

AlexV


People also ask

How do I embed a SWF file?

Embed the SWF content using an object tag, an embed tag, or both. Note: A common web development practice is to use both an object tag and an embed tag to display SWF content in an HTML page. This practice has no benefit in AIR. You can use the W3C-standard object tag by itself in content to be displayed in AIR.

Which tag is used to insert the Flash file in HTML?

HTML <embed> Tag.

Which of the following html5 elements can you use to embed a Flash file in your web page?

Choose File > Publish. Flash will now create the <object>, <param>, and <embed> tags for you. It will also create the classid and pluginspage attributes. Open the HTML document that Flash created, view the HTML source, and copy the code into your HTML page where you want your Flash movie.


3 Answers

<head>
    <script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 
    <script>
    var flashVars = {};
    var params = {};
        params.allowScriptAccess = "always";
        params.allowFullScreen = false;
        params.bgcolor = "#1a1a1a";
        params.wmode = "opaque";

        var atts = {};
        atts.id = "my-swf";

    swfobject.embedSWF("my.swf", "my-swfobject", "100%", "100%", "10.1.0", "playerProductInstall.swf", flashVars, params, atts);
    </script>
</head>
<body>
    <div id="my-swfobject">
        <!-- Any <object></object>, <embed></embed>, and everything else here will be rendered for users without JavaScript. If JavaScript is on, SWFObject will destroy div#my-swfobject and replace it with object#my-swf. -->
    </div>
</body>

Let me know if this is what you're looking for. I can elaborate more if needed. You might also consider suggesting that your IE6 slaves install Google Chrome Frame: http://code.google.com/chrome/chromeframe/

like image 79
Casey Avatar answered Oct 17 '22 01:10

Casey


Here it is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
    <head>
        <title></title>
        <script type="text/javascript" src="swfobject.js"> </script>
        <script type="text/javascript">
            swfobject.embedSWF('test.swf', 'myFlash', '320', '240', '9.0.0', '/swfobject/expressInstall.swf', 0, 0, 0);
        </script>
    </head>
    <body>
        <div>
            <object id="myFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240">
                <param name="movie" value="test.swf">
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="test.swf" width="320" height="240">
                <!--<![endif]-->
                    <p>Version ???</p>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
    </body>
</html>
  • I combine the static and dynamic methods of SWFObject
  • The static part is using the nested-objects method
like image 33
AlexV Avatar answered Oct 17 '22 02:10

AlexV


What I've done in the past is statically put my flash content in a div (using both object and embed tags), and then have SWFObject overwrite the contents of that div when it loads. This will be as close to what you want to do as you can get.

like image 1
Brad Avatar answered Oct 17 '22 00:10

Brad