Using FABridge and swfobject together

June 5th, 2008 by Ryan

Although there’s no visible Flash on Photosleeve, we use some of the Flash image processing capabilities when you upload photos through the site.

There are all sorts of different ways to include Flash, but after some research and poking around, we decided to go with swfobject.

All was swell at first, as we were using ExternalInterface to call between Flash and JavaScript. But that got pretty burdensome once we got past the proof-of-concept phase. Thankfully, we found the Adobe Flash AJAX Bridge (hereafter FABridge), which automatically handles exposing things, marshalling params, etc. It’s really great, actually.

So we had everything working great in IE, but Firefox was a no go. After debugging through things for a while (thanks, Firebug!) I realized that FABridge requires you to use the ‘embed tag within an object tag’ method (is that the one called Flash Satay?). Since I was using swfobject, no dice.

I found that the fix was just to comment out the bit of code in FABridge.js that looked for the Embed tag for certain user agents (see diff at the bottom of this post).

Incidentally, I also discovered that if you have more than one object tag on the page, you must include the bridgeName flashvar for FABridge to figure things out. The syntax for swfobject looks like this:

// swfobject_fabridge_example.js (Sample Code)
swfobject.embedSWF(
    mySwfFile,
    mySwfAlternateContent,
    myWidth,
    myHeight,
    myMinFlashVersion,
    myExpressInstallUri,
    { bridgeName: 'myBridgeName' },
    { allowScriptAccess: 'always' }
);
// and later ...
var flash = FABridge.myBridgeName.root();

You have to get rid of lines 113 and 148-169, below is a diff. FABridge.js has the MIT License blazened at the top, so have no fear when deleting huge portions of it.

--- a/fabridge/src/bridge/FABridge.js 2008-02-11 06:44:57.000000000 -0800
+++ b/fabridge/src/bridge/FABridge.js 2008-05-13 18:17:25.000000000 -0700
@@ -110,7 +110,7 @@
 {
     var searchStr = "bridgeName="+ bridgeName;

-    if (/Explorer/.test(navigator.appName) || /Konqueror|Safari|KHTML/.test(navigator.appVersion))
     {
         var flashInstances = document.getElementsByTagName("object");
         if (flashInstances.length == 1)
@@ -145,28 +145,28 @@
             }
         }
     }
-    else
-    {
-        var flashInstances = document.getElementsByTagName("embed");
-        if (flashInstances.length == 1)
-        {
-            FABridge.attachBridge(flashInstances[0], bridgeName);
-        }
-        else
-        {
-            for(var i = 0; i < flashInstances.length; i++)
-            {
-                var inst = flashInstances[i];
-                var flashVars = inst.attributes.getNamedItem("flashVars").nodeValue;
-                if (flashVars.indexOf(searchStr) >= 0)
-                {
-                    FABridge.attachBridge(inst, bridgeName);
-                }
-
-            }
-        }
-    }
-    return true;
 }

 // used to track multiple bridge instances, since callbacks from AS are global across the page.

Tags: , , , ,

5 Responses to “Using FABridge and swfobject together”

  1. Derek & Ryan Says:

    Looks like someone else ran into this problem and posted a similar solution to the swfobject wiki earlier today:

    http://code.google.com/p/swfobject/wiki/flex

  2. joahns Says:

    If you are using the FlexBuilder 3 “Create Ajax Bridge…” option (available by selecting your project and right-clicking) generates the required bridge proxy javascript from the AS classes / MXML components you specify and also generates a swfobject 2.0 compatible FABridge.js file.

  3. joahns Says:

    Update: I was wrong about FlexBuilder 3 “Create Ajax Bridge…” - the generated FABridge.js works correctly with MSIE with swfobject 2.0 but not with Firefox. Firefox will display the swf but “FABridge” is not defined.

  4. fengfei Says:

    I use FlexBuilder 3 “Create Ajax Bridge…” to generate FABridge.js .With the generated FABridge.js ,if have more than one object tags ,it just works fine with FireFox ,but not with MSIE7(and I have included diferrent bridgeName for each).MSIE displays the swf,but shows errors “FABrige.bridgeName is null or not defined”.

  5. Michael Says:

    Check the latest Flex SDK (3.2.0) - it contains FABridge.js that works fine with multiple objects under IE 6 & 7, Firefox and Safari

Leave a Reply

© 2008 Inner Fence, LLC