Generate Random Quotes with Flash 5 and PHP

32343 Users read it.
by chief monkey (June 15, 2001)
This tutorial will show you how to grab a quote, at random,  from a text file using PHP, and display the result within Flash

User Rating (58 votes)
1 review available | Read the reviews »
Server Model:PHP ImpAkt 1(UD4), PHP MySQL (DWMX), PHP PHAkt 1 (UD4)
Technologies:Flash
In this tutorial we are going to look at how to make a random quote generator using PHP and Flash
You can download the source file here
If you open the source folder you will see 4 files.
quotes.php
quotes.txt
quote.fla
quote.swf
Open quote.fla you will see the movie has 2 layers
Both layers only have 1 frame
The actions layer contains all the actions required to load the variable
The quotebox layer contain the box the text will appear in.
Double click on Frame1 in the actions layer the actionscript panel will open and you will seethe following code.
loadVariablesNum ("quotes.php?noCache="+Math.floor(random(1000000)/random(1000)), 0);
Let's look the code
loadVariablesNum
This simply tell flash to load the variables

The next line is the important part so we will break it down
("quotes.php?noCache="+Math.floor(random(1000000)/random(1000)), 0);

quotes.php
This is the file to load the variable from

?noCache="+Math.floor(random(1000000)/random(1000)), 0);
This code generates a random number to attach to he variable call so that you don't call the same file twice.
Well you do actually call the same file every time, but the URL is different so the browser wont cache it)
Thanks to Jesse at www.actionscripts.org for his help on this.
So we have set up the actions to call the file which holds the variable
but how do we display it
  next >>>

User Reviews

Total of 1 review
there's a typo in the PHP code
Written by kumar mcmillan on September 28, 2002

the line: if($number_quotes!==0){$number_quotes.=-1;}; should be: if($number_quotes!==0){$number_quotes+=-1;}; I am using PHP 4.2.2 - - perhaps this was tested on an older version? I didn't know the concatanate operator would ever convert to int ...

Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency