Back to Top
The nuts and bolts for
Creative web development

Generate Random Quotes with Flash 5 and PHP

This tutorial will show you how to grab a quote, at random,  from a text file using PHP, and display the result within 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.
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
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);

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 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 >>>

Share this Article


there's a typo in the PHP code

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 automatically... so maybe this wasn't tested at all. Either way... great tutorial to show the very basics of loading PHP text variables. This is what I was looking for.