This is part 1 of a 3 part tutorial. The parts are:
Part 1: A simple setup that will send variables from a Flash movie to a PHP script and then that PHP script will print the variables out.
Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.
Part 3: Sending variables from Flash to a PHP script. Saving those variables to a text file, then calling them back into Flash to form a guestbook/shoutbox/tagboard within Flash.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[size=4]Flash Player set-up[/size]
First you need to set up the input boxes. Create an Input box by using the “Text tool” In the text properties box, you must give the input box a name. It doesn’t matter what the name is, but you must remember that name because we are going to be using it in the PHP script in a few minutes.
In my file I made three input boxes. I named them “name”, “age”, and “eye”. Simple enough right? Ok, now we have to make the button to open up the PHP page. To open up a new page from Flash we use getURL(). The code that I used looks like this:
submit.onPress = function () {
getURL ("getVars.php", "_blank", "POST");
}
getVars.php is the name of the PHP file that is our target.
_blank makes the button open up a new page.
POST is the method in which to transfer the variables. The other option is GET.
Thats it for the Flash part.
[size=4]PHP Page set-up[/size]
The PHP code is simple:
<?
// Recieving the variables.
$name = $_POST['name'];
$age = $_POST['age'];
$eye = $_POST['eye'];
// printing out the variables
print "Your name is ". $name . ".<br>";
print "You are ". $age ." years old.<br>";
print "You have ". $eye ." eyes.<br>";
?>
Now a quick explanation of the code:
The first three lines recieve the variables from the scripting using $_POST[]; This is necessary because the more recent versions of PHP have global variables turned off by default. On some hosts, your script will not work without using this method. You can name the variable whatever you like on the left of the equal sign ("="), but on the right, you must put the variable of your input text box.
The second 3 lines print out the strings. The extra periods (".") in there are used to connect the strings together. Its called the concatenation operator. For more about that go here: Click Here!
[edit]Sorry, I had to take out the script in action link because the server that the script was set up on was taken down.[/edit]
I am going to be re-writing this as a real tutorial to be posted on Kirupa’s main tutorial page. But I wrote this up while it was fresh in my mind. Hope it helps.
Cheers,
Jubs :crazy: