You will use a ColdFusion component to get values from the database and send them to Flash (see Figure 2).
Figure 2. Interaction between Flash, ColdFusion, and your database
To write the CFC, follow these steps:
Create a new CFC by choosing File > New > General > Dynamic Page > ColdFusion Component (see Figure 3) and then clicking Create.
Figure 3. Creating a CFC in Dreamweaver
Copy and paste the following code in the CFC. It defines a method to insert a new record into the database:
<cfcomponent hint="Insert and Get Users Comments">
<!--- Define a function to add comments --->
<cffunction name="InsertNewComment" access="remote" returntype="string" hint="Add new comment">
<!--- Define required parameters --->
<cfargument name="FirstName" type="string" required="yes">
<cfargument name="LastName" type="string" required="yes">
<cfargument name="Email" type="string" required="yes">
<cfargument name="Message" type="string" required="yes">
<!--- Get Current Date --->
<cfset Date="#DateFormat(Now(), 'yyyy/mm/dd')#">
<!--- Insert new record into the DataBase --->
<cfquery datasource="GuestBook">
INSERT INTO tblContent
VALUES('#FirstName#',
'#LastName#',
'#Email#',
'#Date#',
'#Message#')
</cfquery>
<!--- Specify result as string --->
<cfset result="Your comment has been added successfully.">
<!--- Return result of the function --->
<cfreturn result>
</cffunction>
</cfcomponent>
This method, InsertNewComment, requires five parameters to insert
a new record into the database: FirstName, LastName, Email, Message,
and Date.
The user enters the first four parameters; ColdFusion generates Date at
runtime automatically.
To obtain a list of all records, append the following code below the previous function (after the closing </cffunction> tag but before the closing </cfcomponent> tag):
<!--- Obtain Comments ---> <cffunction name="GetComments" access="remote" returntype="query" hint="Get a list of comments"> <!--- Get all fields from DataBase ---> <cfquery datasource="GuestBook" name="Info"> SELECT * FROM tblContent ORDER BY "Date" DESC </cfquery> <!--- Return result of the function ---> <cfreturn Info> </cffunction>
Now that you have built the ColdFusion component, you can create its Flash interface.