A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Dynamic_Content

Categories Creating a simple Guest Book in Flash
Author: Jeffrey F. Hill | Website: http://www.flash-db.com |

 
Page 4
«prev 1 2 3 4 5 6 7 next»

Part II - Setting up the script

The below script is the only one that is needed.  The script included in the download has extra comments and other helpful information.  After reading over the script, read over the line by line comments located below.  That combined with the extra comments in the actual script should give you a good idea on how this script functions.  What it basically does is writes to a text file if the variable Submit from the Flash movie is equal to yes, separates the comments into an array then loads that array according to what the values for NumLow and NumHigh are.  In this manner we load 10 entries at a time from the text file.

	<?
1)		$Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
2)		$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
3)		$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
4)		$Website = eregi_replace("http://", "", $Website);
5)		$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~]", "", $Website);
6)		$Name = stripslashes($Name);
7)		$Email = stripslashes($Email);
8)		$Website = stripslashes($Website);
9)		$Comments = stripslashes($Comments);
10)		if ($Submit == "Yes") {
11)			$filename = "GuestBook.txt";
12)			$fp = fopen( $filename,"r"); 
13)			$OldData = fread($fp, 80000); 
14)			fclose( $fp ); 
15)			$Today = (date ("l dS of F Y ( h:i:s A )",time()));
16)			$Input = "Name: $Name
Email: $Email
Website: $Website
Comments: $Comments
Date: $Today

.:::."; 17) $New = "$Input$OldData"; 18) $fp = fopen( $filename,"w");  19) fwrite($fp, $New, 80000);  20) fclose( $fp );  21) } 22) $filename = "GuestBook.txt"; 23) $fp = fopen( $filename,"r");  24) $Data = fread($fp, 80000);  25) fclose( $fp ); 26) $DataArray = split (".:::.", $Data); 27) $NumEntries = count($DataArray) - 1; 28) print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&Guest Book="; 29) for ($n = $NumLow; $n <$NumHigh; $n++) { 30) print $DataArray[$n]; 31) if (!$DataArray[$n]) { 32) Print "

No More entries"; 33) exit; 34) } 35) } ?>

Lines 1-3,5:  These lines include some regular expressions that remove unwanted characters from the variables.  The most important character that we are removing  is the colon (:). (If the colon was not removed someone could potentially enter the same pattern that we are using to separate the text file into an array with and cause results to become mixed up).    These lines are however optional, you can remove them and the script will still work. 

Line 4: This replaces the string 'http://' when it is encountered in a submitted URL.  This part is removed so that when we add the 'http://' part back later we do not have two http://'s.

Lines 6-9:  These  lines are optional.  Basically what the stripslashes() function does is to remove slashes that where added to the data when posted from the Flash movie. 

Line 10: This line checks to see if the variable 'Submit' is equal to 'Yes'.  If it is the script will create a new entry in the database/textfile.  If not it will skip this step and move on to the second part of the script.  Remember that 'Submit' was set to 'Yes' when the user filled out the entry form and submitted it.

Line 11: The variable $filename is given the value of 'GuestBook.txt' which is the text file that we will be writing the new guest book entry to.

Line 12: Opens the file 'GuestBook.txt' for reading.

Line 13: Reads in the contents of 'GuestBook.txt' and assigns that value to the new variable '$OldData'.

Line 14: Closes the file that we previously opened.

Line 15: Gets the current date and time from the server and assigns it to the variable $Today.

Line 16: Formats all of the values entered by the user into a string.  Notice how we add the html formatting at this point.  Also notice the last part of this string that contains the pattern .:::. - we will be using that pattern to separate the text files into an array that we can split up and work with later.  That is  the most important part of this script

Line 17: This line takes the New Input and puts it in front of the old data from the text file.  In this way the newest results are always first.

Line 18: Opens the file 'GuestBook.txt' for writing.

Line 19: Writes the new data to that file.  Notice the limit of '80000'.  This is a fairly large number and you may want to reduce it.

Line 20: Closes the file for writing.

Line 21: Ends the if Statement that we started on Line 10.

Line 22: The variable $filename is given the value of 'GuestBook.txt' which is the text file that we will be writing the new guest book entry to. (Basically the same as on Line 11 although it's needed again because this script has a duel purpose).

Line 23:  Opens the file 'GuestBook.txt' for reading.  As above this line is basically the same as Line 12.  Because this script is not always used for adding a new entry we need to use it again.

Line 24: Reads in the contents of 'GuestBook.txt' and assigns that value to the new variable '$Data'.  

Line 25: Closes the file that we previously opened. 

Line 26: Splits the data that we just retrieved ('$Data') from the text file into an array.  The string is split whenever the script encounters the pattern '.:::.' - remember we added this after every new entry on line 16.  Now we have an array of strings split by the specified pattern in the variable $DataArray.  We can access any of these substrings in the array by specifying $DataArray[i]; where i is the specific Guest book entry number.

Line 27: This line just counts the number of times we matched the pattern '.:::.' in the previous line.  This corresponds to the current number of Guest Book entries that are in the Guest Book.   We send this value back to the flash movie so we know how many people have signed the Guest Book.

Line 28: This formats the first part of the string we send back to the flash movie. Notice how this line ends with 'GuestBook=' we will be adding the Guest Book entries with the next couple of lines.

Line 29: This sets up a For Loop.  We specify the starting value to be equal to NumLow (remember back to the flash movie).  Then we keep looping (increasing $n by 1) while $n is less then NumHigh.  

Line 30: Prints the corresponding Guest Book entry from the array to the string we are returning back to the Flash movie.  By limiting it to only returning 10 at a time we increase it's speed and manageability.

Line 31: Checks to see if their is a value for that Guest Book entry.

Line 32: If the Guest Book entry is empty we print out a message telling the user -  'No More Entries'.

Line 33: At which point we exit the loop.

Line 34: Closes the If loop - (The one that checks to see if their are any more entries).

Line 35: Closes the For Loop.

And that's it.

«prev 1 2 3 4 5 6 7 next»

» Level Advanced

Added: : 2001-12-21
Rating: 8.95 Votes: 191
Hits: 9606
» Author
Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content and applications. Specialty's include SQL, PHP, Perl, and XML.
» Download
Download the files used in this tutorial.
Download (55 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs