SWFObject 1.4.1 update

I’ve just updated SWFObject to v1.4.1. This update is a very small update that fixes a very annoying bug that will only affect people who are using Flash Media Server, or presumably some other method of playing streaming data. If you aren’t using Flash Media Server, or don’t know what that is, you probably don’t need this update, as that’s the only change with this new version.

It was updated to address a bug in Internet Explorer when using innerHTML to embed swf files. Since everyone will be using innerHTML (or Javascript in some way) to embed their swf files, I suspect this will be a bigger issue as time goes on. So if you see the bug, just grab the latest SWFObject and you should be fine.

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 ;)

10 years of Flash

This month marks the 10 year anniversary of what used to be known as FutureSplash Animator. Back then it was just a little animation tool, and has a pretty interesting story behind it, including being turned down by Adobe.

As it grew close to shipping time, we changed the name of our software to FutureSplash Animator to focus more on its animation capabilities. We also were growing tired of running a company that didn’t have much money to spend, and began trying to sell our technology. After an unsuccessful pitch to Adobe and turning down a bid from Fractal Design, we shipped FutureSplash Animator in the summer (May) of 1996.

So how do you celebrate 10 years? Well, there were a few things happening on Monday that are pretty big news: We saw one of the biggest US Television networks go online and offer streaming versions of their shows. This was exciting for me because Schematic designed the UI for the ABC player, and acted as a Technical liaison (with our VP of Multimedia stuff Robert Reinhardt heading that side up). A while back I was asked to help out with a motion test/technology demo for the 3D rotating images, and after a few hours of messing around with Andre Michelle’s the excellent DistortImage class by Thomas Pfeiffer (based on Andre Michelle’s code), we had a nice little working prototype running. It’s very basic, but you can check it out here if you want to see how the animation progressed as the ABC folks built the actual player.

Then Adobe redesigned their site — killing Macromedia.com in the process. At first I thought ‘sure another website, blah blah,’ but then I looked under the hood and noticed that they are using SWFObject to embed the Flash movies on the site(!). It’s a customized version, but the base functionality is all there, and they even left in my namespacing, so if you search the js file for ‘deconcept’ you’ll see the code show up. Pretty cool.

There’s one other big project that was launched on Monday but I’ll save that for another post.