It's Saturday morning, and there are plenty of things I should be doing, instead here I am compiling a tutorial. It's important that you have a fairly sound understanding of ColdFusion and how information is passed between databases and applications. The ColdFusion code is actually fairly simple, and mostly contained in one loop function. Having said that, if you encounter any difficulties please post your questions to the board so others can learn too. Half the fun will be solving it yourself. Honest.
Guestbook.fla
The guestbook file is virtually identical to the one which runs the 'perl' version. I only slightly reset a few values on one of the frames. Otherwise like that version you need to tell it where to reference the guestbook entries.
There are two places this occurs:
1. In the frame labelled start. (This is for calling in the entries to the Flash file.)
2. On the submit button. (For sending the new entry to the database.)
You need to change the
Load Variables ("http://www.yoursite.com/guestbookentries.cfm", "", vars=POST)
to the location of your guestbookentries file.
Variables are called in from the database by using the 'POST' method. It is possible to use 'GET' but remember, this appends the data in the query string, and is good only for a few thousand characters.
If you're lost at this point of the tutorial, either you don't have enough knowledge or I'm delivering this information poorly, either way you should go outside and feed the fish.
That's all as far as the flash file is concerned. The rest is ColdFusion and database stuff.
Firstly a quick note. The following code has been tested using Microsoft Access. I've not tried it with anything else, however, there is nothing fancy going on, so it should works just fine in the likes of SQLServer7 etc.
Microsoft Access
The Access database consists of 6 fields in one table (visitorFullname,comment,dateOfMessage,live,visitorEmail,homepageURL). It's very simple to set up, but hey, if you want it, there's a zip copy with just one entry in the download at the bottom of this page (guestbookmdb.zip)
The 'live' field (above) is the only addition to text we are accessing. I've used this in a small content managment application, which views all the entries in the guestbook and allows you to edit, delete or disable entries. There are no instructions here, but a copy of this application is available in the download for this tutorial (guestbookadmin.zip).
This file is only ever called by the Flash movie, so we don't really need to do a check for the existence of variables beforehand. They will already exist.
So here we go. Set your datasource.
The variable 'todo' is used in both calls and if it is set to 'sign'.
then let's sign the guestbook by inserting a new entry. All the information we need comes directly from the Flash movie.
INSERT INTO guestbooktbl(visitorFullname,comment, dateOfMessage,live,visitorEmail,homepageURL) VALUES( NULL '#name#', NULL '#comment#', #CreateODBCDateTime(Now())#, 1, NULL '#email#', NULL '#url#')
Now let's read all the entries in the database and store the results in order of the date they were entered. Most recent first.
SELECT * FROM guestbooktbl WHERE live=1 ORDER BY dateOfMessage DESC
That's the database done with. Now set up a couple of variables Flash needs.
I'm unsure why, but Flash needs the 'end of file' (eof=true) value first, in order to work. I haven't really looked into this, heavens I've spent long enough on it already. Variable 'count' is the amount of entries Flash will be working with.
Now loop through the results of the above query and append it all to the variable 'data'
#data#
It may seem obvious but i'll mention it anyway. We are not actually pushing any information into Flash. Rather flash is just coming to get what it sees as a text file. The only thing on this page flash sees when it is harvesting information is the output of the variable 'data'.
The final guestbookentries.zip is also available in the download at the bottom of this tutorial.
Have fun one and all.
David.
| » Level Advanced |
Added: : 2000-09-11 Rating: 7.93 Votes: 158 Hits: 10023 |
| » Author |
| No information about the author has been provided |
| » Download |
| Download the files used in this tutorial. |
| Download (1159 kb) |
discuss this topic to forum
