Let s Begin: ColdFusion Components (CFCs)

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.

  • cfcomponent Used only once; it defines a block of code as one CFC. They are a lot like objects in that they can have their own methods and properties.

  • cffunction This tag is used to define one function or method. The functions we will create will be used to interact with your data source.

  • cfargument This tag is used to define an argument in a function.

  • cfquery This tag is used to define a query. This enables you to use SQL statements to query the database.

  • cfreturn Returns a value from the function to Flash. In this chapter, the tag will return the results of a query.

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.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net