[SWFObject] SWF does not play on first load (both IE and FF)

Sander Kruger s.kruger at 3-gsp.com
Wed Dec 20 09:46:17 PST 2006


Hello,

I'm new to this list. I worked through the November and December archive but
didn't find a solution. I have a problem with my Flash app wrapper using
either SWFObject 1.5 or the Adobe wrapper:

When a Flash app is loaded for the first time, it doesn't play. The player
just shows the background color. I use Flex/AS3 and Flash Player 9. This
occurs both in IE6 and in FF1.5.0.8. If the browser finds the SWF in the
cache, no problem. But if not, it doesn't play.

Does anyone know how to make sure the application starts automatically,
every time?

Here's some more diagnostics about the problem:
To get the movie to start, I can either select 'forward' from the context
menu (FF only), select 'play' from the context menu (IE and FF) or refresh
the page (IE only).

So far I've tried:
. disabling the pre-loader
. setting the 'play' and 'loop' params
. to no avail.

I did manage to create 2 workarounds in FF, neither being a very elegant
one:
1) ------------------------------------------------------
add an alert after the so.write('flashcontent'). The code becomes:

    var so = new SWFObject("TestObject.swf", "TestObject", "100%", "600",
"9");
    so.useExpressInstall('expressinstall.swf');
    so.addParam("loop", "false");
    so.write("flashcontent");

    alert( "application is starting" );

Somehow, the alert makes the Flash movie start. confirm() works as well, but
I didn't find any less intrusive commands that do the trick.

2) ------------------------------------------------------
Add a timer to kick off the play after loading. The code looks like this:

    var so = new SWFObject("TestObject.swf", "TestObject", "100%", "600",
"9");
    so.useExpressInstall('expressinstall.swf');
    so.addParam("loop", "false");
    so.write("flashcontent");

    setTimeout( 'tryPlayFlash();', 1000 );

    function tryPlayFlash()
    {
      if (document. TestObject)
      {
        if (document. TestObject.Play)
          document. TestObject.Play();
        else
          alert('Cannot communicate with ActionScript');
      }
      else
        alert('Can\'t find the Flash movie');
    }

This is a rather bad one because it will restart the movie if it plays
correctly.

And I haven't found any of this to work in IE. If you have encountered the
same problem, please let me know if there is a workaround.

Regards,
S. Kruger




More information about the Swfobject mailing list