|
That just about covers what happens in the Flash movie, but what about the ColdFusion server stage? If you've used ColdFusion to insert records into a database table and send emails then most of this code will be familiar to you.
Here's the template in its entirety:
<cfsetting enablecfoutputonly="yes">
<cfparam name="form.txtName" default=" ">
<cfparam name="form.txtEmail" default=" ">
<cfparam name="form.txtAddress" default=" ">
<cfparam name="form.txtComments" default=" ">
<cfparam name="form.bAcceptMailing" default="false">
<cfmail from="guestbook@artafterscience.com"
to="adrian.marshall@leadhat.co.uk"
subject="artafterscience guestbook" >
Entry in the guestbook from #form.txtName#
email: #form.txtEmail#
address: #form.txtAddress#
#form.txtComments#
</cfmail>
<cfquery name="qInsComments" datasource="guestbook">
INSERT
INTO comments ( guestName, guestEmail, guestAddress, comments, acceptMailing )
VALUES ( '#form.txtName#',
'#form.txtEmail#',
'#form.txtAddress#',
'#form.txtComments#',
<cfif form.bAcceptMailing IS "true">1<cfelse>0</cfif> )
</cfquery>
<cfquery name="qGetID" datasource="guestbook">
SELECT max(ID) As GuestID
FROM comments
</cfquery>
<cfcontent type="application/x-www-urlform-encoded">
<cfoutput>ID=#qGetID.GuestID#&cfStatus=1</cfoutput>
It's not particularly robust, but this is just an example.
In fact you could do more or less anything you can do with Cold Fusion in this routine that doesn't generate any output. The important bits as far as this tutorial is concerned are the last two lines. Flash expects data in URLform encoded format, so use CFContent to set the appropriate MIME type.
The last line returns the actual data as name value pairs separated by ampersands. In this example two variables are returned, ID and cfStatus. You can return any data you want in this way and it will be available within the Flash movie after the data loaded event fires.
That's a fairly simple but useful example of how you can use Flash and ColdFusion together. Once you've grasped the concepts of passing data between the two programs there are endless possibilities, so to help you on your way I've provided a copy of the source for you to to download, deconstruct and experiment with.
|