SWFObject, ExternalInterface and Internet Explorer

I was working on something earlier today, and became so frustrated with it that I just got up and went home early for the day.  I was very pleased with the work I had completed to this point, and as soon as I launched the dreaded Internet Explorer browser to ‘test compatibility’ … I immediately threw my arms up in the arm and spouted out a handful of expletives.

I created a very simple Video player in Adobe Flex 2.0, and exposed all of its functionality through ExternalInterface so that a javascript framework I am working on could communicate with it — allowing for ‘media controllers’ (play, stop, pause, forward, backward, rewind, progress, etc) could be rendered to the page using HTML and CSS.  I had the following general code in my Adobe Flex application:

[as]ExternalInterace.addCallback(‘startPlayback’, play);
ExternalInterface.addCallback(‘stopPlayback’, stop);
// …. more calls for other events

I dropped a reference to my compiled SWF onto the page using the latest SWFObject 2.0, recently released on Google Code. I even back-ported it to the last 1.5 release on blog.deconcept.com, when it failed initially … assuming, of course, that the 2.0 release was still ‘buggy’.  I stood corrected.

I did some research, and found a few posts related to the issue, one that I found more or less ‘ensuring’ was Mihai Bazon’s.  He basically stated that to accomplish the ExternalInterface integration to my page, I’d have to load my SWF’s with the initial page … well, this is sort of a ‘oops, would have been nice to know this AHEAD OF TIME’ thing, as it makes quite a few changes to the framework a requirement.  Especially since Flash Video’s are going to be one of the driving forces to the end result.

So, with that … Mihai suggests that you can load the SWF’s dynamically still, if you load them into an IFRAME.  This seems like a logical solution, but I had another alternative idea … which is to use Flash’s LocalConnection system to ‘relay’ the events, and simply loading a small lightweight ‘listening server’ on the page at ‘page load’ which can be passed the ‘destination’ and the ‘method’ with ‘arguments’.  Now, to pull this off, all dynamically loaded SWF’s on the page would have to implement the same basic startup process … Which would go something like:

Pass a static param into the ‘listener server’, this represents it’s “LocalConnection Name” that it will listen on

Pass the same param into all the dynamically loaded SWF’s that will ‘attach’ to the ‘listener server’

Once the dynamically loaded SWF is done, in it’s “creationComplete” it can simply connect to the ‘listener server’ and ask to be an event handler.

When you have javascript on the page that needs to execute some ActionScript in a dynamically loaded SWF, the Javascript can tell the ‘listener server’ and then the ‘listener server’ can basically ‘relay’ the information to the handler.

Now, I’ve only thought about this for a few minutes … and I haven’t tried to put it into practice, not sure if I can ‘late bind’ “external interface callbacks” with the “early-load” SWF … or if all the “addCallback” methods have to be executed as part of the “creationComplete” process or not.  Knowing what I know so far of ActionScript and Flash, I’m thinking it’s just some sort of a goofy limitation either with the Flash Player 9 Plugin … or with the way Internet Explorer allows plugins access to the page’s JavaScript run-time.

Either way, I’ll probably be trying to put one of the two idea’s into practice, as it will be a required feature set for the framework I’m building.

I’ll write more about the final solution, and possibly some example code for those who may be struggling with the same issue.

2 comments for “SWFObject, ExternalInterface and Internet Explorer

  1. sdfg
    March 26, 2010 at 4:14 pm

    Change the names of your callbacks. Callbacks named “play” or “stop” don’t work in IE. Check out the as3 language reference for ExternalInterface, and read the comments at the bottom.

  2. February 10, 2011 at 10:20 pm

    Thanks so much for this comment! You just saved me hours of pain.

Leave a Reply