4

The following code embedding a Flash animation into an HTML document using SWFObject displays only the alternative content. Why?

<!DOCTYPE html>
<html>
    <head>
        <title>Adding a Flash Movie</title>
        <script type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js">
        </script>
        <script type="text/javascript">
            swfobject.embedSWF("flash/bird.swf", "bird", "400", "300", "8.0.0");
        </script>
    </head>
    <body>
        <div id="bird">
            <p>An animation of a bird taking a shower</p>
        </div>
    </body>
</html>

Chrome, IE and Firefox all show just An animation of a bird taking a shower.

The code is a sample from the book HTML & CSS: design and build websites.

4
  • Flash support is removed from lot of recent browsers. Please check browser compatibility before using it. Commented Nov 30, 2016 at 10:43
  • Flash support is not being removed from browsers. Rather, Flash is now enabled only after a 'ask to activate' popup. Unfortunately, swfobject does not function with this newer scheme. Commented Dec 23, 2016 at 15:19
  • 1
    Flash will reach its end of life in 2020, @Chris. Till then, browser vendors will gradually limit the use of Flash, till they ultimately drop its support completely. See the link I edited into your answer. Commented Oct 1, 2017 at 10:44
  • Loading https://get.adobe.com/flashplayer/ in a hidden iframe will prompt the user for permission to run Flash. See Flash Roadmap for Chromium and the answer I got this info from. Commented Oct 1, 2017 at 10:58

2 Answers 2

15

SWFObject 2.2 no longer works properly. The bug in SWFObject has already been reported on GitHub, but the library is unmaintained.

The new “HTML by default” Flash policy starting at Chrome 55 does not initialize the variables that SWFObject uses to detect whether Flash is installed. Specifically, navigator.mimeTypes no longer contains application/x-shockwave-flash, unless Flash is enabled by the user. Other browsers have similar issues related to the click-to-run activation scheme introduced as part of Flash’es end of life.

At this time, the best course of action may be to simply use <object> to embed Flash. For example:

<object type="application/x-shockwave-flash" data="app.swf">
    <param name='movie' value="app.swf"/>
    <param name='bgcolor' value="#999999"/>
    <param name='FlashVars' value="var1=Hello&var2=Goodbye" />
    <param name='allowscriptaccess' value="sameDomain"/>
</object>

Note that (1) the .swf is specified in two places (2) only the movie param is required; the other params are shown here as an example of what is possible.

Sign up to request clarification or add additional context in comments.

Comments

4

Chrome's since version 55 does not initialize the variables that swfobject needs to detect if Flash is installed. You can apply primitive patch to swfobject js to skip hasPlayerVersion check:

-       if (hasPlayerVersion(swfVersionStr)) { // create SWF
+       try {  // create SWF
            var obj = createSWF(att, par, replaceElemIdStr);
            if (att.id == replaceElemIdStr) {
                setVisibility(replaceElemIdStr, true);
            }
            callbackObj.success = true;
            callbackObj.ref = obj;
-       }
-       else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
-           att.data = xiSwfUrlStr;
-           showExpressInstall(att, par, replaceElemIdStr, callbackFn);
-           return;
-       }
-       else { // show alternative content
+       } catch (e) {  // show alternative content
            setVisibility(replaceElemIdStr, true);
        }

2 Comments

Might as well change hasPlayerVersion() to return true all the time?
No, because it will not show replaceElemIdStr in old browsers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.