Flash Remoting takes some of the pain out of connecting Flash movies to dynamic content via ColdFusion. This article offers a complete demonstration of using Flash Remoting with ColdFusion Components.

The necessary tools
The following items are needed for the examples in this article:

  1. ·        Flash Remoting Components—Download Flash Remoting Components.
  2. ·        ColdFusion MX—A trial single-user version is available for download.
  3. ·        Flash MX—A trial version is available for download.
  4. ·        Microsoft Access—The simple database used for this demonstration is in .mdb format (Access), but any database will do as long as your table has the same name and field names as the one in this demonstration (Datasource name: flash_cf, table name: siteContent).
  5. ·        The demonstration files—Download the files used in this demonstration.

There are five steps for integrating Flash Remoting with ColdFusion Components.

Step 1: The data source
Open the Access database (from the downloaded .zip file) that accompanies this article and register in ColdFusion MX Administrator. You’ll notice a table named siteContent. Inside siteContent there are four fields: pageID, pageTitle, pageText, and pageLink. Figure A shows a snapshot of the Access database.

Figure A
Snapshot of Access database

Step 2: Install Flash Remoting Components
Flash Remoting Components allow Flash to talk to ColdFusion and vice versa. A simple breakdown and installation instructions can be found at Macromedia’s Web site.

Step 3: The ColdFusion Component
Access the ColdFusion Component (CFC) from the .zip file you downloaded (Flash_CF.cfc) and view the source. ColdFusion’s new CFCs are self documenting, meaning they can automatically share information about their methods and properties. Basically, CFCs are collections of functions called methods. They can have as many methods as you care to define. Instead of attributes (used in custom tags), CFCs use arguments that assume the arguments’ scope when they are called through methods.

We’re going to use a CFC to query our Access database and display the data in Flash.

First, take a look at the CFC. Open Flash_CF.cfc and you’ll notice a simple method called getPageAll. The method getPageAll contains a <cfquery> called Everything that selects all the fields in table siteContent of datasource Flash_CF. The method getPageAll will return this query object to the Flash MX movie via Flash Remoting.

Since many CFCs can be grouped together (packaged), it’s generally a good idea to save them in their own directory. Make sure Flash_CF.cfc is in a directory called Cfc.

Step 4: The Flash interface
Open flash_cf.fla from the downloaded .zip file in Flash MX and you’ll see four layers: actionscript, dynamic content, layout, and background (Figure B). Click in the actionscript layer and open the Actions Panel.

Figure B
Sample Flash interface

Connect to Flash Remoting Services. The code in Listing A connects to Flash_CF.cfc and exposes all of its methods.

Populate the interface with data. On the dynamic content layer, you’ll find the textboxes site_title, Instancename_0, and site_link. We’ll populate with data with the actionscript function presented in Listing B.

You’ll notice that the textbox site_link will contain data that is formatted in HTML. This is one way you can link to Web sites from Flash. Click on the site_link textbox and you’ll see that the HTML formatting button is selected.

Step 5: Test your application
The final step is to test the application. You should publish the Flash movie and watch the simple Flash interface bring in data from the Access database via the CFC. Figure C shows a snapshot of the Flash movie.

Figure C
Sample Flash movie snapshot