ColdFusion, WDDX, and Flash (Page 2 of 8)

For the purposes of this tutorial I will assume you have knowledge in all of the products listed in the Prerequisites Section of the Introduction page. Things like creating a database in Access, configuring your Flash movie and querying a database will not be covered here.


If you have all the required software installed and operating correctly, now would be a good time to download the tutorial source files. Included in the source file archive is:

  1. Employees.mdb (Access database)
  2. FMX_Employees.fla (FlashMX file)
  3. F5_Employees.fla (Flash5 file)
  4. index.htm (Embeds the published Flash file as Employees.swf)
  5. qry_getEmployees.cfm (ColdFusion template used to retrieve the Employees)
  6. wddx.as (ActionScript file)

After you've downloaded the source files, create a new directory on your web server where you want to place these files. Name the directory wddxTutorial and unzip the source files into this directory. All of the files above are easily recognizable except perhaps the wddx.as file. This file contains Flash ActionScript code and was originally included in the WDDX Serializer/Deserializer written by Branden Hall and Dave Gallerizzo. The serializer/deserializer is an extension you can install into the Macromedia Extension Manager. Because this extension does not install the same for Flash5 and for FlashMX I decided to include the ActionScript in the source files to alleviate you from having to download the extension from Macromedia.


Now that we've got all that out of the way let's get down to business. The basic idea of the tutorial is this: We're going to create a Flash movie that calls a ColdFusion template. The ColdFusion template will query the database and ask it for some information. In our case, we'll ask the database to give us all the Employee information it has in the Employees table. This information will be stored in a ColdFusion query result-set. Code will then be written to serialize this query into a WDDX packet (which is simply XML) and write this packet to the screen. Flash, having called the ColdFusion template will read in the packet and parse the packet for display in the Flash movie. Thus, creating a dynamic Flash movie that displays information retrieved from the database. Flash in this instance is our presentation layer and the database is our data layer. ColdFusion is the middle layer that allows the presentation layer and the data layer to communicate freely.


Let's take a look at the Employees database. It's a really simple database consisting of one table Employees that has four columns: EmployeeID, FirstName, LastName, and PhoneExtension. In order to allow our ColdFusion template to retrieve information from this database and eventually have Flash read it in, we need to create a datasource. Open up your ColdFusion Administrator and create a datasource called Employees that maps to the Employees database we just looked at.