Tutorial details:
Written by: Jesse Stratford
Time: 20 - 30 minutes
Difficulty Level: Intermediate
Requirements: Flash 4 or 5, a server that supports PHP, (or similar).
Topics Covered: How to keep track of variables between pages.
Assumed knowledge: Variables, Paths, Button Actions, Conditional Statements, Basic HTML.

To see this in action, type a value in the variable field below and press 'Send'.

The source for this tutorial includes the PHP files I used in my example above as well as the traditional FLA sources.

Before we being, a few words on PHP. PHP is a Server Side scripting tool which allows you to process data before it's seen by the end user. Basically it allows you to create dynamic HTML pages. You could just as easily use CGI, ASP or JSP to achieve the outcome we're after in this tutorial, but I chose PHP because it's (a) Free and easy (b) What I know :o)

The First File (pass.fla)

OK, download the source and you will see that my first Flash file is called pass.fla. Inside pass.fla is a simple imput text field with the variable name 'value' and a button with this code:

on (release) {
 getURL ("middle.php", "_blank", "GET");
}

The important line above is the getURL command. So let's break it down:

  • middle.php is the name of my PHP document which represents the intermediate file in which we want to keep track of the variable passed from Flash. If you were making some sort of order form in Flash and you wanted to show people snapshots of their options or something, this file, middle.php could be where you would list the snap shots. Basically it can contain anything, so long as it's still a PHP file.
  • _blank is the target window, you don't need to use a target window but I did so that people who used the example above wouldn't be taken away from this tutorial when they clicked 'Send'
  • GET specifies the method we're using to send our variables. You can use either GET or POST. Basically GET shows up in the URL line and is easier to debug while POST doesn't and isn't.

The Second File (middle.php)

This file contains a lot of junk to pad it out but the most important line is line 12 which reads:

click <a realsrc="end.php?value=<?php echo $value; ?>" href="http://www.actionscript.org/dev/admin/end.php?value=<?php echo $value; ?>">here</a> to end your variable back

As you can all see this is a standard HTML link with some funny jargon added. The jargon between the <? and ?> tags is PHP and all it says is "Fetch the vale variable and write it's contents here". So if I were to have types 'test' in the pass.swf file above, this line would be outputted as:

click <a realsrc="end.php?value=test" href="http://www.actionscript.org/dev/admin/end.php?value=test">here</a> to end your variable back

Understand? The one important thing to note is that if you change the name of the variable you are passing around, you need to change the name in the call. So if I were to change the input field variable to "abcd" my code should be:

click <a realsrc="end.php?abcd=<?php echo $value; ?>" href="http://www.actionscript.org/dev/admin/end.php?abcd=<?php echo $value; ?>">here</a> to end your variable back

So, when clicked this link will load up end.php, and using the GET method (they way we have included the variable in the URL is the traditional HTML form of the GET method), it passes our variable across.

The last file is discussed overleaf...