Tutorial details:
Written by: Jesse Stratford
Time: 20 - 30 minutes
Difficulty Level: Intermediate
Requirements: Flash 5, a server which supports PHP version 3 or higher.
Topics Covered: loadVariablesNum, conditional clauses, goto actions, fopen() [PHP], fwrite() [PHP].
Assumed Knowledge: Variables, Paths, Basic knowledge of FTP/HTML/UNIX syntax, and Flash of course.

Click here to download the source for the above movie.

Hey people, welcome to the Dynamic Counter tutorial. In this tutorial we will investigate how to create a hit counter for your flash page. OK let's get into it!

Before we start with flash we need to create a data-storage file. This is just a text file called 'counter.txt', which you can create with your favorite plain text editor. Note the some text editors might try and store your text in Rich Text format, which will cause you problems. I'm using Windows Notepad, which comes with all versions of Windows and can be accessed through Start > Programs > Accessories> Notepad).
Create your text document, and enter the following code:


Now save your document as counter.txt in the directory you plan to use for your Flash counter. Now, briefly, I will explain what you have just done and why. The purpose of this file is to store data for us to read and adapt for use in our counter
count=0 - sets variable count to the value 0 (zero).
& (ampersand symbol, Shift-7) - indicates the end of one variable and the beginning of another
loaded=1 - sets the variable loaded to the value 1, I'll explain why later.

Now call up Flash 5 and create a new document (Ctrl-N). Save your file as "counter.fla" in the same directory as your counter.txt file. Now create a new Movie Clip Symbol (Ctrl-F8) and name it 'counter'. Leave it empty for the moment. Open up your Library (Ctrl-L) and drag one copy of your empty 'counter' clip onto the stage. Select that instance of your symbol and name it 'counter' using the instance panel (Ctrl-I).
Now right click the counter instance and select Edit, (or Ctrl-E).
Create 3 keyframes within the counter symbol stage, at frames 1, 2 and 3. Double click frame 1 to bring up the Actions panel for that frame. Now enter the following code:

if (startup eq "") {
 startup = "Run Already";
 loadVariables ("counter.txt?" add random(2000), "/counter");

Note the best way to enter code is to just copy it from here and paste it (using Expert Mode) into your actions panel. This is one of the joys of Flash 5. To access Expert Mode use Ctrl-E or click the right-facing menu arrow atop the Actions window and select Expert Mode from the drop down menu.