Let's Begin: ColdFusion Components (CFCs)
Now the fun begins. We have established the structure for our website. We have created a ColdFusion data source. Next, we will discuss how to communicate with ColdFusion. ColdFusion Components (CFCs) are the preferred method to bridge the gap between Flash and ColdFusion.
The filename of the extension .cfc will be used as the service name in ActionScript. In other words, if we name our CFC myCFC.cfc, within Flash our service name will be myCFC. Think of your CFC as a container that holds a lot of tasks (functions). To communicate with any of the functions, you need to call the container namein this example, myCFC.
CFCs are composed of ColdFusion tags that allow you to create functions and return the results to Flash. The main ColdFusion tags that we will be using in this chapter are cfcomponent, cffunction, cfargument, cfquery, and cfreturn.
The structure of a CFC is as follows:
<cfcomponent displayName="componentFileName"> <cffunction name="function1" access="remote" returnType="string"> <cfquery name="myQueryName" datasource="myDataSource"> /// your statements go here </cfquery> <cfreturn myQueryName> </cffunction> <cffunction name="function2" access="remote" returnType="string"> <cfreturn "PUT SOME TEXT HERE"> </cffunction> </cfcomponent>
Macromedia Dreamweaver MX or later has a built-in editor that will assist in the creation of CFCs. To take advantage of this feature, create a new file and save the file as C:\unleasedCafe\unleashedCom.cfc.
If you do not have Dreamweaver MX or later, you can simply open a text editor of your choice and save the file as C:\unleasedCafe\unleashedCom.cfc.
After your CFC has been saved, you can start creating your component. The first CFC that we will create will be used to test our Flash Remoting connection.
Type the following:
<cfcomponent displayName="unleashedCom"> <! Establish a Flash Remoting Connection > <cffunction name="getTestConn" access="remote" returnType="string"> <cfreturn ". . . connection successful"> </cffunction> </cfcomponent>
Save your file.
That's it! You now have a component with one function called getTestConn. Next, you will learn how to call this function from Flash.