Requirements      
Prerequisite knowledge Required products
Sample files
User level
  • Developers who are exploring tutorials in the Flex and ColdFusion mini learning center that are based on the Fictitious Sales Planner example.
  • Experienced ColdFusion developers without previous Adobe Flex framework or Adobe Flash Builder 4 experience.
  • ColdFusion developers who are familiar with ColdFusion components.
Adobe ColdFusion Enterprise Edition (2016 release) (Download trial)
Flash Builder (Download trial)
All
       

 

 
Introduction

 

Adobe Flash Builder 4, formerly known as Flex Builder, has simplified the integration of Adobe ColdFusion with the Adobe Flex framework to create SWF applications. You can now use simple wizards to import ColdFusion components (CFCs) into your projects and access data through service calls to the CFC functions. You can also easily populate Flex UI controls with the returned data by simply clicking-and-dragging the data object onto the control.
 
Many of the tutorials in the Flex and ColdFusion mini learning center use the same sample database with employee sales information for the Fictitious Sales Planner. In this tutorial, you will learn how to set up a ColdFusion data source and Flash Builder project, and use the Flash Builder Data Services wizard to import a CFC for a sample application, Fictitious Sales Planner. You will then access one of the CFC operations to return data to the Flash application and populate a Flex framework DataGrid control.

 
Setting up the sample database

 
Time to complete: 15 minutes.
In this tutorial you set up the sample database, and create the Apache Derby data source.
 
Note: The following setup instructions assume that you have a local, standalone installation of the Developer's Edition of ColdFusion 9 Professional
 
Downloading the sample database archive file
In this section you will download the F4CF_FictitiousSalesPlanner database directory. This database contains the employee sales data for the Fictitious Sales Planner sample application, which is used in other tutorials of the Flex and ColdFusion mini learning center.
 
  1. Download thef4cf_fictitious_db.zip sample file if you haven't done so already.
  2. Unzip the file to the \ColdFusion9\db directory and review the contents:
    The \ColdFusion9\db folder now contains the F4CF_FictitiousSalesPlanner folder which contains the control files and sample data for the Derby db.
  3. Start the ColdFusion server.
 
Creating the Apache Derby Data Source
In this section, you will use the ColdFusion Administrator to create an Apache Derby Data Source to access the FictiousSalesPlanner data.
 
  1. Log on to the ColdFusion Administrator.
  2. Expand the Data & Services left hand navigation and Click on Data Sources.
  3. Enter F4CF_FictitiousSalesPlanner as the Data Source Name and Select Apache Derby Embedded from the Driver drop down menu as shown in Figure 1.
Add a New Apache Derby Data Source
Figure 1. Add a New Apache Derby Data Source.
 
  1. Click the Add button.
  2. Click the Browse Server button next to the Database Folder, and navigate to the ColdFusion9\db\F4CF_FictitiousSalesPlanner folder. Click Apply. The Data Source definition panel will appear as shown in Figure 2.
The Data Source definition panel
Figure 2. The Data Source definition panel.
 
  1. Click the Submit button.
  2. You should now see the F4CF_FictitiousSalesPlanner Data Source listed under the Connected Data Sources as shown in Figure 3.
The F4CF_FictitousSalesPlanner Data Source has been added

Figure 3. The F4CF_FictitousSalesPlanner Data Source has been added.

 

You will be testing the installation of the F4CF_FictitiousSalesPlanner data source later in this tutorial.

 
Set up a Flash Builder data service project

 
Time to complete: 5 minutes.
In this section, you will set up a Flash Builder data service project with ColdFusion for use with the Fictitious Sales Planner sample application.
 
Creating a Flash Builder project
A Flash Builder project is similar to a Dreamweaver site. You create a project to store and organize your code files. Follow these steps to create a Flash Builder project:
 
  1. Open Flash Builder 4.
    Note: We assume that you are working with the standalone (not the plug-in) version of Flash Builder 4 . You can install the plug-in version if you are already using Eclipse for your programming environment. However, you will likely see some minor variations in the following steps. We also assume that you have a local, standalone installation of ColdFusion. You may need to make changes to the paths based on your custom installation.
     
  2. Select File > New > Flex Project as shown in Figure 4.
Create a new Flash Builder project

Figure 4. Create a new Flash Builder project.

You will get the new project dialog box. Set up your new project as shown in Figure 5:
 
  • Name the project F4CF_Getting_Started.
  • Be sure to use the default location for this example.
  • In the Server technology section of the dialog box, select ColdFusion from the Application server type drop-down menu. (Note that the Use remote object access service check box is selected by default when you select a server technology.)
  • Select the ColdFusion Flash Remoting option.
Set up your new project in the New Flex Project dialog box

Figure 5. Set up your new project in the New Flex Project dialog box.

  1. Click Next.
 
Connecting to the ColdFusion server
Follow these steps to configure your Flash Builder project to work with your ColdFusion server:
 
  1. In the Configure ColdFusion Server dialog box, select the options for your ColdFusion installation type. Figure 6 shows the settings if you are using the default installation of ColdFusion in Standalone mode on a PC.
Specify your ColdFusion server configuration

Figure 6. Specify your ColdFusion server configuration.

Note: If you have used the default installation of ColdFusion in Standalone mode for a Mac OS X computer, your ColdFusion settings will likely be:
 
  • ColdFusion root folder: /Applications/ColdFusion9
  • Built-in ColdFusion web server web root: /Applications/ColdFusion9/wwwroot
  • Built-in ColdFusion web server root URL: http://localhost:8500
  1. Click the Validate Configuration button to ensure that the settings are correct.
    Note that the location of the Output folder is located within the ColdFusion server web root.
     
    Flash Builder automatically creates a folder named based on the project name and appended with –debug. In this case, the F4CF_Getting_Started-debug folder is where Flash Builder will place the compiled Flash SWF and HTML wrapper files.
     
    Note: If you have the default installation of ColdFusion in Standalone mode for a Mac OS X computer, your Output folder setting is likely /Applications/ColdFusion9/wwwroot/F4CF_Getting_Started-debug.
     
    Remember that Flash source files, unlike ColdFusion source files, are not deployed to the web server. Instead, you compile the source into a SWF file that is referenced in HTML wrapper files. The SWF and HTML files are uploaded to the server.
     
  2. Click Finish to create the Flash Builder project.
You will see the F4CF_Getting_Started project in the Package Explorer, shown in Figure 7. Note also that the MXML application file with the same name is created and opened for editing. Note that Figure 7 shows the MXML Editor tab in Design mode. Click the Source button below the tab to see the Editor in code view.
 
The Flash Builder project in the Package Explorer

Figure 7. The Flash Builder project in the Package Explorer.

The Flex framework provides two programming languages: ActionScript, which is a fully object-oriented language, and MXML, which is an XML-based language with similar syntax to CFML.
 
Note: If you are working through the Getting Started section of the Flex and ColdFusion mini learning center, continue with the following section. If you came to this section from another Flex for ColdFusion developers tutorial, return to that tutorial for your next tasks.

 
Introspect and import a CFC

 
Time to complete: 5 minutes.
Now that your database, data source, and Flash Builder project are set up, you are ready to learn how easy it is to retrieve data from a CFC method and bind it to a Flex user interface element.
 
Introspecting the ColdFusion component
ColdFusion components are a way of organizing your business logic into reusable code. They were introduced in ColdFusion MX and replace the inline database query construct. In other words, instead of putting a cfquery tag at the top of your CFML page, you invoke the query that is placed into a CFC method, passing in arguments as necessary.
 
Note: Refer to the article Understanding the role of CFCs in Flex application development for more information on CFCs.
 
  1. Download and unzip the provided f4cf_getting_started_tutorial.zip file on your local disk if you haven't done so already.
  2. Move the SalesTarget.cfc file to the \\wwwroot\F4CF_Getting_Started-debug directory.
    When you configured the Flash Builder project, a project-specific debug folder was automatically referenced and created as the output location for the compiled SWF and related HTML wrapper files. Since this is a ColdFusion data service project, the debug folder is in the ColdFusion server's web root. Figure 8 shows the CFC in the same directory as the SWF and HTML wrapper files.
     
    Note: Refer to Deployment assets for more information about the SWF and HTML wrapper files. The default Flash Builder compile settings are configured to create these files immediately and whenever the source files are saved.
     
The compiled Flash SWF and HTML wrapper files

Figure 8. The compiled Flash SWF and HTML wrapper files.

  1. Open the SalesTarget.cfc file in a code editor or in a browser.
You will see many CFC methods defined with cffunction tags. Each method contains encapsulated business logic for the Fictitious Sales Planner application. In this tutorial, you will use the getAllData operation to retrieve all employees in the database.
 
Note: Each method has the access property set to remote, which makes the method available for use with SWF applications.
 
Testing the CFC with the sample data source
You will now use the provided test file to ensure the successful setup of the Fictitious employee data source:
 
  1. Download and unzip the provided f4cf_getting_started _db_test.zip file onto your local disk if you haven't done so already.
  2. Move the SalesTargetTest.cfm file to the \\wwwroot\F4CF_Getting_Started-debug directory.
  3. Open a browser and run the SalesTargetTest.cfm page.
    You will see all of the database records in a cfdump display (see Figure 9).
     
The F4CF_FictitiousSalesPlanner employee sales data

Figure 9. The F4CF_FictitiousSalesPlanner employee sales data.

 
Using the Data Services wizard to import a CFC
Next, you will import the CFC into the project using the Data/Services view in Flash Builder:
 
  1. Locate the Data/Services view in Flash Builder shown in Figure 10.
    (If the view is not open, select Window > Data/Services.)
     
The Data/Services view

Figure 10. The Data/Services view.

  1. Click the Connect to Data/Service link to run the Data Services wizard.
    Note: You can also select Data > Connect to Data/Service to open the Data Services wizard. Use this method if you already have a Data Service defined.
     
  2. Select ColdFusion for the service type (see Figure 11).
Select the ColdFusion data service type

Figure 11. Select the ColdFusion data service type.

  1. Click Next.
  2. Name the service F4CF_Getting_Started_Service and configure it as shown in Figure 12.
    Note: The service name is arbitrary. You can name it anything you want; however, it is related to the CFC so you will often see it named similarly. In this case, it might be something like SalesTarget_Service. We have chosen to name the service to match the tutorial.
     
    • Be sure the Import CFC option is selected.
    • Specify the CFC location: Click the Browse button next to the CFC Location field, navigate to the \wwwroot\F4CF_Getting_Started-debug\ directory, select the SalesTarget.cfc file, and click Open.
Configure the ColdFusion service

Figure 12. Configure the ColdFusion service.

Note that the Package is set to services.f4cf_getting_started_service. When you complete the following steps you will see that the project's src folder in the Package Explorer contains a services.f4cf_getting_started_service package. This package contains ActionScript files that are automatically generated by the Flash Builder wizard.
 
  1. Click Next.
  2. In the Remote Service Authentication dialog box, shown in Figure 13, enter your RDS username and password.
    Note: Be sure to have RDS enabled in the ColdFusion Administrator. Remember that the default username is admin.
     
Enter your credentials to authenticate RDS access

Figure 13. Enter your credentials to authenticate RDS access.

  1. Click OK.
    Flash Builder accesses the CFC, introspects it, and returns information about the available operations and data types associated with those operations. You will see each method in the CFC displayed in the Service Operations window shown in Figure 14.
     
The Service Operations dialog displays the CFC methods

Figure 14. The Service Operations dialog displays the CFC methods.

  1. Click Finish.
    Flash Builder creates the service. You may see the instructions shown in Figure 15, if you have not previously selected the check box in the lower left corner of the Using Remote Services dialog box.
     
Instructions for using the remote service

Figure 15. Instructions for using the remote service.

The rest of this tutorial steps you through these instructions.
 
  1. Click OK to dismiss the Using Remote Services dialog box.
  2. Locate the Data/Services view to see the CFC operations shown in Figure 16.
The introspected CFC operations

Figure 16. The introspected CFC operations.

Note that the getAllData() method name is followed by the word Object. When Flash Builder introspected the CFC and provided information about the methods, it mapped the ColdFusion query that is returned from this operation to a generic ActionScript Object data type.

 
Create a simple data display

 
Time to complete: 15 minutes.
Now that the CFC has been introspected into Flash Builder and the Flash Builder project is set up, you will use the returned data to create a simple employee data display.
 
Configuring the data return type
In this section, you will assign your own data type name to the returned data that is retrieved in the CFC method call:
 
  1. Right-click the getAllData() operation in the F4CF_Getting_Started_Service and select Configure Return Type (see Figure 17).
Configure the return type of a CFC method

Figure 17. Configure the return type of a CFC method.

Each record from the query will be placed in an ActionScript object with each column of data (FIRSTNAME, LASTNAME, EMAIL) set in a name/value pair. Each record is indexed starting at zero.
 
Note: Unlike ColdFusion, ActionScript is a zero-indexed language.
 
Instead of generically referring to the returned data as an object, this wizard allows you to give the data a return type name. You will do this next.
 
  1. In the Configure Return Type dialog box, leave the radio button checked for Auto-detect the return type from sample data. (see Figure 18).
Auto-detect the return type

Figure 18. Auto-detect the return type.

  1. Check the box for Remote authentication, and Enter your username and pasword in the Service Authentication window (see Figure 19).
Enter the remoting credentials for the getAllData() CFC function

Figure 19. Enter the remoting credentials for the getAllData() CFC function.

  1. Click OK, and then click Next.
  2. Enter a name to create a new data type. In the field next to 'Array of' , enter the name, EmployeeSalesData (see Figure 20).
Enter a name to create a new data type

Figure 20. Enter a name to create a new data type.

  1. Review the Properties returned by the operation and click Finish.
You can now expand the Data Types category in the Data/Services view to see that the EmployeeSalesData data type is defined as an object that includes EMAIL, FIRSTNAME, and LASTNAME properties (see Figure 21).
 
The EmployeeSalesData data type

Figure 21. The EmployeeSalesData data type.

 
Binding data to a Flex component
After you have configured a method return type, you can easily bind it to components. This section demonstrates how to bind the EmployeeSalesData data type to a DataGrid component:
 
  1. Switch to Design mode in Flash Builder by clicking the Design button below the Editor tab (see Figure 22).
The Design view button

Figure 22. The Design view button.

  1. Locate the DataGrid control of the Components view (see Figure 23).
The Flex Builder Components panel

Figure 23. The Flex Builder Components panel.

  1. Drag and drop the DataGrid component into the Design view of the F4CF_Getting_Started.mxml file as shown in Figure 24.
Add the DataGrid control to your application

Figure 24. Add the DataGrid control to your application.

  1. Drag and drop the getAllData() CFC function from the Data/Services view onto the DataGrid control to populate it with the EmployeeSalesData data type.
  2. Leave the defaults in the Bind to Data dialog window and Click OK. (see Figure 25)
     
Leave the defaults in the Bind to Data dialog window

Figure 25. Leave the defaults in the Bind to Data dialog window.

The DataGrid control now has columns that match the properties in the EmployeeSalesData data type (see Figure 26).
 
The bound DataGrid control

Figure 26. The bound DataGrid control.

  1. Select File > Save tosave the MXML file.
  2. Click the Run (green round) button to test the file(see Figure 27).
Click the Run button

Figure 27. Click the Run button.

Figure 28 shows the DataGrid control populated with the CFC data. Note that Flash Builder has opened the HTML wrapper file from the F4CF_Getting_Started-debug folder in the web root.
 
The DataGrid component populated by the EmployeeSalesData data type

Figure 28. The DataGrid component populated by the EmployeeSalesData data type.

 
Where to go from here

In this tutorial, you set up the HSQLDB engine, a sample database, and a ColdFusion data source. Then you set up a Flash Builder project to work with ColdFusion server technology. Finally, you experienced how easy it
is to retrieve data from a CFC method and bind it to a Flex user interface element.
 
To learn more about how Flex and ColdFusion work together, refer to the following tutorials: