Flex & Ajax Together: FABridge

    March 8, 2006

Macromedia has a lot of wonderful tools for the developer community. One of the most impressive new tools, Flex 2.0, has been developed with ColdFusion integration in mind. Macromedia threw out a new resource by introducing a new library of code called the Flex Ajax Bridge (FABridge). The new code can be inserted into a Flex application, a Flex component or an empty SWF file in order to expose it to scripting in the browser.

Ely Greenfield gave an apt description of the new toy over at Macromedia’s (a division of Adobe) website. He broke things down, explaining what the FABridge is and what to do with it.

To humbly borrow a page from the Ruby on Rails community, FABridge is built with the “don’t repeat yourself” principle in mind. Rather than having to define new, simplified APIs to expose a graph of ActionScript objects to JavaScript, with FABridge you can make your ActionScript classes available to JavaScript without any additional coding. Once you’ve inserted the library, pretty much anything you can do using ActionScript, you can do using JavaScript.

He said Flash Player has the ability, natively, through the External API (ExternalInterface), to call JavaScript from ActionScript and vice versa. He ExternalInterface has some limitations:

The ExternalInterface class requires you, the developer, to write a library of extra code in both ActionScript and JavaScript, to expose the functionality of your Flex application to JavaScript, and vice versa.

The ExternalInterface class also limits what you can pass across the gap – primitive types, arrays, and simple objects are legal, but user-defined classes, with associated properties and methods, are off-limits. You’re limited in what you can do.

The ExternalInterface class enables you to define an interface so your JavaScript can call your ActionScript – FABridge essentially lets you write JavaScript instead of ActionScript.

Next he goes into where to use the FABridge. He says the library may be useful if you want to use a rich Flex component in an Ajax application but don’t want to write a lot of Flex code. If only a couple of people know how to use Flex, this FABridge will allow everyone to use the work of the Flex dudes. Finally, if you’re building an integrated RIA with both Flex and Ajax portions, he suggests on might find it faster to start with FABridge as a head start.

He said there are some limitations on the FABridge in its current state, which is pre-alpha. He said testing has been done on Firefox 1.5 and Internet Explorer 6.0 (SP2). Neither Linux nor Macintosh has been tested.

Because of the limited integration between the JavaScript and ActionScript garbage collection models, the bridge must guarantee that any ActionScript object stays in memory indefinitely once it has been accessed from JavaScript. If you find that memory consumption is becoming an issue in your use of the bridge, you can call the function FABridge..releaseASObjects(). This will clear the cache of bridged objects and functions and allow them to exit from memory as appropriate. After calling this function, all references to ActionScript objects and functions are invalid and must be reacquired.

He ended by saying one can use the FABridge to automatically expose your Flex application to Ajax-based HTML applications. The bridge allows users to “easily embed rich Flex components in applications, integrating them tightly with the rest of the page content and one the Flex app is enabled through the bridge, JavaScript developers have access to all the functionality it provides.”

Tag: |

Add to | DiggThis| Yahoo My Web=

John Stith is a staff writer for WebProNews covering technology and business.