|
2 When Should I Use the Flex AJAX Bridge?
3 What Do I Need to Use It?
4 Download and Installation
5 How Do I Use the Flex AJAX Bridge?
6 What Are the Limitations?
7 How Do I Find Out More?
8 Summary
What Is the Flex AJAX Bridge?
by Ely Greenfield
The Flex™ AJAX Bridge (FABridge) is a small, unobtrusive code library that you can insert into an Adobe® Flex™ application, a Flex component, or even an empty SWF file to expose it to scripting in the browser.
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. After you insert the library, essentially anything you can do with ActionScript, you can do with JavaScript.
Adobe® Flash® Player has the native ability, through the External API (the ExternalInterface class), to call JavaScript from ActionScript, and vice versa. But 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.
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.
View a sample application that makes use of the Flex AJAX Bridge.
Note: You must install Flash Player 9 to view the sample application.
When Should I Use the Flex AJAX Bridge?
The FABridge library is useful in the following situations:
You want to use a rich Flex component in an AJAX application but do not want to write a lot of Flex code. If you wrap the component in a FABridge-enabled stub application, you can script it entirely from JavaScript, including using eval()’d JavaScript generated remotely by the server.
You have only one or two people on your team who know Flex. Although I would strongly encourage everyone to grab a copy of Flex and try it out (you will love it, I promise!), the FABridge library lets everyone on your team use the work produced by one or two Flex specialists.
You are building an integrated rich Internet application (RIA) with both Flex and AJAX portions. While you could build the integration yourself using ExternalInterface, you might find it faster to start with the FABridge as a head start.
What Do I Need to Use It?
To use the FABridge library and samples, you must have the following:
FABridge, which is available within the Flex 3 SDK beta (see below)
Flash Player 9
Microsoft Internet Explorer, Mozilla Firefox, or Opera with JavaScript enabled
Any HTTP server to run the samples
Download and Installation
To run the sample files, follow these steps:
Download Flex 3 SDK beta or daily builds (46-67 MB).
Note: Your use of this site including software downloads, submission of comments, ideas, feature requests and techniques on this and other Adobe maintained forums, as well as Adobe’s rights to use such materials, is governed by the Terms of Use.
Unpack the ZIP file to a local directory.
Browse to the FABridge framework files found within /frameworks/javascript/fabridge
Place the src and samples folders side by side on any HTTP server.
Open a web browser to
Make sure you access the samples through http:// URLs and not file:// URLs. The Flash Player security sandbox may prevent them from working correctly if accessed as local files.
How Do I Use the Flex AJAX Bridge?
To use the FABridge library in your own Flex and AJAX applications, follow these steps:
Add the src folder from the ZIP file to the ActionScript classpath of your Flex application.
If you are compiling from the command line, you can add the src folder to your application by specifying it using the --actionscript-classpath compiler option.
If you are using Flex Builder (optionally get the Flex Builder 3 beta), right-click your application in the Navigator window and select Properties.
Select the Flex Build Path section.
Add the src folder to the class path section. Click OK.
Add the following tag to your application file: