I have created this script using Flash and PHP. Data is saved and retrieved through
PHP and displayed in Flash movie in HTML format. ASP version of the same Guestbook
is available under ASP section.
Steps
=====
Start a new flash movie. Insert a new Dynamic text box and give it name txtmain and
don't forget to check the HTML option. Insert a dynamic text fields status which
will be used for displaying messages. Insert a new layer, name it action and place
following code in action window.
lowlimit and highlimit are the flash variables that would be send to PHP script.
First time data range from record 1 to record 10 will be displayed in HTML enabled
text box.
Insert two new button instances for up and down scrolling
For Up Button
=============
on (release) {
txtmain.scroll--;
}
For Down Button
=============
on (release) {
txtmain.scroll++;
}
Above code is self-explanatory.
Add two button instances for Next 10 and previous 10 records and add the following
code in action window.
Code for next Button
====================
on (release) { // Increase limits by 10
lowlimit = Number(lowlimit)+Number(10);
highlimit = Number(highlimit)+Number(10);
txtmain = "Processing Entries from "+lowlimit+" to "+highlimit+" Please wait ::: ";
loadVariablesNum ("guestbook.php?lowlimit="+lowlimit+"&highlimit="+highlimit, 0);
}
Code for Previous Button
========================
on (release) {
if (lowlimit == "0") {
txtmain = ":::: Nothing before Zero ::::";
}else{
lowlimit = Number(lowlimit) - Number(10); // dec. limits by 10
highlimit = Number(highlimit) - Number(10);
txtmain = "Processing Entries "+lowlimit+" to "+highlimit+" Please wait for a
while :::::: ";
loadVariablesNum ("guestbook.php?lowlimit="+lowlimit+"&highlimit="+highlimit, 0);
}
}
Add three dynamic text fields to the movie for Total entries(totalentries),Low Limit
(txtll) and High Limit (txthl) respectively.
Now Insert a new movie instance. Place four dynamic text boxes for name(textname) ,
email (txtemail) , website (txtwebsite) and comments (txtcomments). Add two buttons
for Submit and Reset.
Code for Submit Button
======================
on (release) {
if (txtname eq "") {
_root.txtmessage = "Name information missing.";
} else if (txtemail eq "") {
_root.txtmessage = "Email missing.";
} else if (txtcomments eq "") {
_root.txtmessage = "Comments missing.";
} else if (txtwebsite eq "") {
_root.txtmessage = "Enter the URL to your website";
} else {
submit= "Y"; // this variable will be used in PHP script to determine whether the
new data has submitted or not.
If data is submitted
====================
<?
If (isset($submit)){
if ($submit=="Y"){
$datestamp =(date ("dS F Y ( h:i:s A )",time())); //current date
$fpn=@fopen("guestbook.txt","a+"); //open guest book txt for append mode.
@flock ($fpn,2);
$rec = "Name: <b>$txtname</b><br>Email: <b><u><a
href=\"mailto:$txtemail\">$txtemail</a></u></b><br>Website: <b><u><a
href=\"$txtwebsite\" target=\"_blank\">$txtwebsite</a></u></b><br>Comments:
<b>$txtcomments</b><br><i>Posted on: $datestamp" . "\n"; // store data in HTML
format
$fw=fwrite($fpn,$rec);
@flock($fpn,3);
@fclose($fpn);
}
}
?>
Read Data from Guest Book Database Store all entries in a Array.
================================================================
<?
$fp=@fopen("guestbook.txt","r");
@flock ($fp,2);
$garr=array();
while ($line=@fgets($fp,1024)){
array_push($garr,$line);
}
$totalent=count($garr)-1;
if ($totalent<0){
$totalent=0;
}
if($highlimit>$totalent){
$highlimit=$totalent;
}
?>
Following code will be used for sending variables to PHP script.
<?
print "&txtll=$lowlimit&txthl=$highlimit&totalentries=$totalent&txtmain=" ;
?>
If u remember txtll,txthl,totalentries and txtmain are dyanamic text boxes we have
created in flash movie.
<?
if (count($garr)==0){
print "<br><br><b> :::: Nothing to display :::: </b>";
exit();
}
$ar=array_reverse($garr); // reverse the array
$garr=array();
for($i=$lowlimit;$i<=$highlimit;$i++){ // filter the records between lowlimit and
highlimit
if (!$ar[$i]) {
print "<br><br><b>::: Nothing Below This :::</b>";
exit;
}
print $ar[$i];
print "<br><br>";
}
@flock($fp,3);
@fclose($fp);
?>