Tag Archive: SWFFormFix

UPDATE 25Feb2008 – Adobe has published the recommended workaround for this problem.

This is another major release – I rewrote some of the code with some inspiration from Zelph.com’s onDOMload as suggested by Geoff Stearns, Author of SWFObject. I have now optimized the code to the point where all you need to do is include it in the head of your document and as the page loads, each object will be fixed, so by the time the page is done loading, everything is fixed automatically!

———EDIT 19Jan2007———
I found yet another IE bug related to this topic. After a page is cached by IE and reloaded, the SWF is loaded before it’s embedded, so any callback functions the the SWF tries to setup when it loads (like the JS->Flash ExternalInterface code) will fail with an error “objectID” is undefined. Then when you try to use the callback function you get Object doesn’t support this property or method because the functions didn’t get assigned to the Flash object properly.

To fix this error you need to put this line above your SWFObject code (or above your <object> tag):

window["objectid"] = new Object();

Here’s an example document:

You can download SWFFormFix2 Here:

You can see the nicely formatted and highlighted source code here:

I have patched the newest version of SWFObject (1.5) to include FlashFormFix 1.0.0. If you use this version in place of the standard SWFObject it will automatically apply SWFFormFix (bugfix for ExternalInterface() in a Form with IE) when you use it – this means all you have to do is replace your standard swfobject.js with the new swfobject_swfformfix.js and you’re done!

Here’s the optimized version:
(to download it right click and “Save Link As” or something similar)

Here’s the human-readable version in case you want to see what I changed:
(to download it right click and “Save Link As” or something similar)

I just finished SWFFormFix 1.0.0 – a BIG update from the 0.1.0 prerelease! This new version introduces Auto Mode which takes care of everything for you! All you need to do is include the script in you and call SWFFormFixAuto() before the closing tag!

For more specific instructions or to download it go here:

(to download it right click and “Save Link As” or something similar)

This version also contains an updated version of the previous function “SWFFormFix()” that is more optimized and probably faster than the Auto version.

It seems every time I try something new I need to fix other people’s problems to get it to work, arrrrg! [:(] I decided to try use Flash 8’s ExternalInterface() class to communicate with the Javascript function on my page. I liked the sound of this method because I can pass an array of arguments with it and return a variable back from the Javascript to my Actionscript – all in one command! I whipped something up real quick and bam! it works! Then I moved the SWF into it’s destination: the middle of an HTML form – to my amazement it didn’t work! I was using Internet Explorer 6, so I tried Firefox 2.0 and it worked fine. It also worked fine in Firefox 1.5 (a little less compatible) and even Opera 9.00 Beta! Wow, seriously IE – you got beat by Opera Beta [:P]. It also failed in IE7. To make a long story short, I spent 6+ hours trying to figure out what was wrong – finally I realized the code was fine and it was a IE bug. There’s a bunch of speculation and suggested fixes on the Adobe / Macromedia Flash 8 ExternalInterface() LiveDocs page, but they’re either overly-complicated or they don’t work. So I sat down and figured it out, then I made my own fix, which I consider to be very easy :D.

Here’s the solution: SWFFormFix by me, Steve Kamerman 😀. Here’s the deal, basically, you need to trick Internet Explorer because if you put an object in a form, IE’s implementation of Javascript seems to want to look for “window.yourObject” and not “document.form[x].yourObject”, so my script figures out which form you are in and makes an alias at the wrong location that points to the right location. Don’t believe me? Try it out.

Here are some examples:
A SWF outside of a FORM (using SWFObject to embed)
A SWF inside of a FORM (using SWFObject to embed)
A SWF inside of a FORM (using std Flash EMBED tags)
A SWF inside of a FORM (using SWFObject and SWFFormFix)

As you should see, SWFFormFix fixes the problem and leaves you with zero errors – plus it’s free!

Download SWFFormFix:

1. Include the swfformfix.js script in the head of your document

<script type="text/javascript" src="swfformfix.js"></script>

2. Run the SWFFormFix(yourObject) command on your SWF.

Example with SWFObject (recommended):

<div id="swfdiv_ttpreview" style="width:200px;height:100px;">
This is replaced by the Flash movie.
<script type="text/javascript">
// <![CDATA[
 var so = new SWFObject("myMovie.swf", "myMovieObjectName",
"200", "100", "6.0.0", "#ffffff");
 so.addParam("quality", "high");
// ]]>

Example with std Flash EMBED tags:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
width="200" height="100" id="myMovieObjectName" align="middle">
<param name="movie" value="myMovie.swf" />
<param name="quality" value="high" />
<embed src="myMovie.swf" quality="high" width="200" height="100"
name="myMovieObjectName" type="application/x-shockwave-flash" />
<script type="text/javascript">
// <![CDATA[
// ]]>

If you are still using the old school EMBED tags, you should really get with the program and start using SWFObject!! SWFObject (by Geoff Stearns) not only cleans up your code, but it removes the annoying gray box around your Flash movies in Internet Explorer 7 (or earlier with updates). I made a nice little script called HTML2SWFObject a couple months back that converts your old EMBED code to SWFObject code – check it out!