SWFObject 1.4.4 released

There was a new bug intruduced in the 1.4.3 release of SWFObject, so if you are using 1.4.3, you should upgrade to 1.4.4 immidiately.

The issue is that onbeforeunload is being triggered even when a user clicks a link that contains a javascript link, which causes the cleanup routine to trigger, which makes all your swfs on the page dissapear in IE.

This has now been fixed, and 1.4.4 includes all of the ‘fixes’ that are needed to date, including the streaming media fix, and the Flash Player 9 ‘out of memory’ errors.

Download Now

* One new issue that can arise with the addition of the cleanup routines, is if you are including the swfobject.js script in your pages more than once, you will cause more ‘out of memory’ errors. If this happens, make sure you only insert the swfobject.js file in your page only one time.

SWFObject 1.4.3 released

Please note that there is an issue with this version of SWFObject. When clicking links that use href=”javascript:” in them, it triggers the new onbeforeunload, which makes all your swf files dissapear. All users should upgrade to 1.4.4.

This release only contains a single fix for a new issue that occurs when using Flash Player 9.

If you have multiple swf files embedded in a single HTML page, and at least one of those files uses ExternalInterface to add a callback, when you leave the page you will get an error that says “Line 56: Out of Memory”.

This only occurs in IE – no other browsers are affected, and it only happens when using Flash Player 9 whether you are using SWFObject or not.

The problem is in some new Javascript code that was inserted into Flash Player 9 to fix a bug in the IE browser. This IE bug affected swf files that connected to streaming media servers – to learn more about it you can read this blog post.

After working with Adobe, we came up with a Javascript fix for the streaming media issue and I used a variant of this code in the 1.4.2 version of SWFObject. All was fine then, until Flash Player 9 was released, and it turns out Adobe included their own Javascript (that is very similar to the fix in SWFObject) to fix the streaming media problems in IE. The only problem is that the code they used doesn’t like it when there is more than one swf embedded in a page.

So to get to the point, this new version of SWFObject just removes the ‘bad’ code that Flash Player 9 inserts into the page and instead uses the cleanup code from the previous version of SWFObject that has been working fine for Flash Player 8.

Go grab a copy now – anyone using ExternalInterface needs to be aware of this issue and should upgrade their SWFObject script immediately if you have any pages with more than one swf embedded in it.

Here’s a direct download link, or you can get it out of the SVN repository, or visit the SWFObject page and get it from there.

SWFObject 1.4.2 update

I’ve just packaged up SWFObject 1.4.2. (Direct download link)

This is a general maintenance release that fixes a couple of bugs, and improves version detection in Internet Explorer. Here’s the changelog:

  • [updated] added one more fix for a related issue to the audio streaming bug listed below, thanks to Ben Longoria for the fix – this should take care of all the streaming audio issues, if you are still having problems after this update, please let me know
  • [updated] updated the detection code for IE/ActiveX browsers to fix a crash that could occur when the user had Flash Player 6.0.21 or 6.0.23 installed (Thanks to Michael Williams at Adobe for the code to fix this (and the Adobe detection kit))
  • [fixed] updated the getQueryParamValue method to fix a bug that would return the wrong value if you had two variables that ended with the same string (Thanks to Aran Rhee for discovering the issue and providing a fix)
  • [fixed] fixed a couple of strict js warnings that crept back in sometime after the 1.4 update

I’ve also created a Subversion repository for SWFObject. If you are familiar with SVN, you can do a checkout from http://svn.deconcept.com/swfobject/.

Go get it!

Flash Player bug with streaming content and innerHTML in IE

A few weeks back some Schematic developers were working on a video player for NBC Universal*. They found a very odd bug: when watching a video, if they hit F5 to reload the page, or closed the popup window, if they were using IE, the audio would keep playing until the video ended or until they closed all their open Internet Explorer windows.

After spending a few hours investigating, Danny noticed that when they weren’t using SWFObject to embed the swf, they didn’t have the problem. So they called me late on a Sunday night to help figure out what the problem was. To make a long story short, the issue was this:

When you embed a swf using innerHTML in IE 6, and stream content to the Flash Player, when the user leaves the page (either by reloading it, hitting the back button, or closing the browser window with another browser window open), the audio will keep playing until the video ends or until the user closes all of their open IE windows.

Working with another developer, we found a very odd resolution at first – if we removed the Id attribute from the object tag, it would fix the problem – no more ghosted audio. The downside to this was that it also broke ExternalInterface calls going into the swf. I tried many other ways to reference the swf, but it seemed that without that Id attribute there, Flash Player wasn’t able to add the Javascript hooks to the page when the plugin was loaded.

After that I started playing with all kinds of different methods including using document.write instead of innerHTML, (which fixed the issue) but the drawback of using this was so great I kept looking for another way to fix it. Without innerHTML, I would have to change the way SWFObject works, move the placement of the Javascript code on the page, and then add more code to clear the alternate content before writing the swf to the page. All of this made that option unacceptable. I also tried using DOM methods to embed the swf file, but that ended up being such a headache I quickly gave up on that as well. Using the DOM to embed plugins is the fastest way to a headache: you think CSS is bad cross browser? Try getting plugins to work…

At this point I gave up, and e-mailed a couple of Adobe contacts. Luckily I’ve had a lot of contact with them lately because of the Devnet article and the whole FlashObject name change thing, so I figured they owed me anyway ;).

I put together a test case (HUGE thanks to Gene Dymarskiy at IBCTV for setting me up with a stream from one of their servers to test against – Gene sent an e-mail to the SWFObject mailing list the day after we found this bug, so was also eager to find an answer to it) and sent the details over to Adobe and waited for them to check it out. A while later, I got some Javascript code back from a Flash Player engineer that with a little tweaking, fixed the problem. Here’s the code that I’ve added to SWFObject:

/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
  var objects = document.getElementsByTagName("OBJECT");
  for (var i=0; i < objects.length; i++) {
    for (var x in objects[i]) {
      if (typeof objects[i][x] == 'function') {
        objects[i][x] = null;
      }
    }
  }
}
if (typeof window.onunload == 'function') {
  var oldunload = window.onunload;
  window.onunload = function() {
    deconcept.SWFObjectUtil.cleanupSWFs();
    oldunload();
  }
} else {
  window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}

As you can see, it simply checks the page for object tags when the page unloads and loops through their properties looking for functions, and if it finds one, it sets it to null. I’m assuming this is cleaning up some leftovers Flash Player inserts because of the new ExternalInterface stuff, but I haven’t looked too deep into the cause of it.

I’ve just updated SWFObject to v1.4.1 to include this code. If you are using streaming content, this update is a must – if not, you can hold off as this was the only change to the code.

UPDATE: I realized this morning that the title of this post is slightly misleading – this is not a Flash Player bug, but a bug in Internet Explorer 5 and 6 in the way the browser handles the Flash Player. The issue doesn’t exist in IE 7.

UPDATE 2: It seems that there is still one issue remaining with this that can’t be solved. I haven’t tested it extensively, but it appears that when you leave a page using a link from within a Flash movie, the audio will continue, but if you leave the page using the back button or using an HTML link, the audio will be stopped. The bug was introduced when Microsoft introduced the Eolas changes, so it may be fixable in a future update. I’ll post more info here as I get it.

UPDATE: The latest SWFObject (v1.4.2) fixes all of the known isues with this, so if you are still seeing the problem, go update and you should be fine.

* If you want to check out the player, which has TONS of great content loaded into it, you can try these urls:

The player was built so it can be re-skinned on the fly for all the different networks or shows. Dig around a bit, there’s so much great content in there – especially some of the Conan and SNL stuff.

SWFObject on Adobe Developer Center (Devnet)

Well, after a couple of months of waiting on Adobe Legal to decide that I couldn’t use ‘FlashObject’ any more, here’s the Devnet article on SWFObject.

If you are already familiar with the script, you probably won’t get anything new from the article, but if you are new to it, you should head over and give it a read. It’s basically the SWFObject page, only profesionally edited and tidied up.

Go have a look.

Also, in case you missed it, Adobe.com now uses a slighly customized version of SWFObject for their site wide Flash Player detection and embedding.

Also, notice the humping unicorns on my t-shirt I’m wearing in the photo I gave them ;)