Monday, April 28, 2008

Flash to Javascript calls in Internet Explorer

I was having trouble getting a Flash that uses "FSCommand()" to send messages to javascript on a page working in Internet Explorer 7 (this applies to other versions too I'm assumming).  Worked fine in Firefox just having the

function flashEmbedID_DoFSCommand(command, args) {}

javascript function defined somewhere in the page.  But the same setup in Internet Explorer seemed to not be getting any calls from the Flash.

Internet Explorer runs Flash as an ActiveX component instead of a plug-in like Firefox does.  I had already read somewhere that you need to use VBScript to get a call from Flash in IE, and then make a subsequent call to javascript.

I tried this right away, but still no go. After days of sandbox testing and googling one thing after another, I somehow came up with just the right mix of words to feed Google and came back with a possible fix (NOTE: I'm using the latest version of SWFObject 2 for javascript-based standards compliant Flash embedding, which is similar to UFO and actually replaces it (along with SWFObject 1.5, which was not so similar to UFO)). Follow the rabbit trail:


Q Why doesn't fscommand work in Internet Explorer?
A In order to make fscommand work in Internet Explorer Adobe recommends to add a block of VBScript to capture and forward the FSCommand calls to JavaScript. However VBScript doesn't work anymore when a Flash movie is inserted using innerHTML, like UFO does. Fortunately you can also use JavaScript instead of VBScript to catch the FSCommand calls. A small downside is that it uses proprietary attributes, however wrapped in conditional comments you will keep your code valid. A sample page can be found here.

I'm not sure his explanation exactly fits my problem, since I tried not using SWFObject, just using a straight <object> embed, and it still did not work in IE.  I'm guessing ASP.NET or something else broke the VBScript FSCommand subroutine calls working for me, so using the javascript with the proprietary "event" and "for" attributes was still a great solution.

No comments:

Disqus for A Nofsinger's Blog