Flex Ajax Bridge (FABridge) Library

fabridge

The Flex-Ajax Bridge (or FABridge) is a very cool features. It enables you to automagicaly create a “bridge” between your Flex application and the JavaScript code embed in your web page. This way you can call methods of your Flex application directly in your JavaScript code, and the other way around.

There are several solutions to use the FABridge in your Flex project. Those are the most common:

Both solutions have issues. The first one is the fastest, no doubt, but it creates a LOT of JavaScript code that you might not need at all. But you will still have to deploy and maintain that JavaScript code in order to get the FABridge working properly. The second one is a bit more complicated and create no useless JavaScript code. Nonetheless, you’ll have to add an external source directory to your Flex project and this reference might come to be broken (if someone else download the sources for example).

After the jump, discover the ONE solution that has it all…

The idea is simple: instead of adding an external source directory to our Flex application, we are going to create a Flex Library that will contain the FABridge sources. This can be done really easily in Flex Builder 3:

  • Click “File>New…>Flex Library Project”. Name it “FABridge” and click “Finish”.
  • In this new project, create a new “bridge” package.
  • In this new package, copy the FABridge.as file located inside the FABridge framework directory (“C:\Adobe\Flex Builder 3\sdks\{SDK_VERSION}\frameworks\javascript\fabridge\src\FABridge.as” by default)
  • And that’s it!

Now, if you want to use the FABridge inside one of your projects, simply add this FABridge project to your library path and voila! You can also copy the compiled FABridge.swc library (from your \FABridge\bin folder) in the “libs” folder of your project.

  • Ravi

    Flex Bridge is not working with Popup rather than creating bridge in Main application could u pl help

    • Promethe

      The bridge works between one HTML page and one SWF.
      If you open a popup, it’s another HTML page and another SWF.

      Maybe you can use LocalConnection to sync. multiple SWF on multiple pages. But I never actually used LocalConnection so I can’t help you with that 🙁

  • Ravi

    Hi can u pl tell me I am creating bridge on popup and all callback are initialize once and only 1 time all goes fine but when I close popup and open again it don’t work because it has lost all callback references so can u help me how I can persisten it… Thanks Ravi