This tutorial is going to show you a very basic method of sending information from Flash to an external PHP script. This*is merely a primer to get you working with using Flash*for forms and dynamic content.*The actual code for this tutorial can be used IN lower versions of Flash, but the actual process is written for Flash MX 2004.
Here is the example that we are going to create - http://flashnewz.com/examples/namesubmission.html
Creating the Flash Document
To begin our tutorial we are going to create our Flash document. Open Flash and create a new Flash document. On the stage take your text tool and draw a text box.
Now highlight the text box and hit F8 so we can convert our text box to a symbol. We are going to change our text box into a button. The reason we are doing this is so we can add the "Hit Enter Key" function so the user can simply hit enter rather than having to press the submit button.
Once you have converted the text box to a symbol double click the text box so we can edit the text box. In the variable area type in "name". This is going to be used when sending information to our PHP script.
Now go back to our main stage area, where we will add our "Hit Enter Key" actions. Open your actions panel and select your text box. In your actions panel under Global Functions/Movie Clip Controls double click the "on" and select keyPress "<Enter>".
In the actions pane click before the } tag because our getURL command has to come before the close of the actionscript. Under Global Functions/Browser/network double click the getURL action. Now in our actions we are going to add a link to our php script, window, and method. I named my PHP name.php. Make sure that you use the GET method for this example. Here is what your actionscript should look like:
This completes the textbox area of our FlashMovie. To add another button so the user can click as I have added in my Flash movie you simply repeat this process, but use the on (release) function.
Now export your movie.
Now it's time for our PHP script.*
Since the PHP is so simple for this example I am going to paste the code and let you copy it, name it name.php and let you use it from there.
Notice that we used "name" in our php script to reflect the variable in our Flash movie? If you change the variable name in our Flash move we also need to change the value in our php script.
Hello <span class="style1"><? echo $_GET['name'];?></span>,</p>
As you can see, our Flash movie has sent the information you entered into the text field to the PHP script displayed here.
Now upload both of them and test it out. If we did everything properly the SWF file should send the information to the PHP script, which will show the name once the user submits the data.
If you have any questions or comments feel free to post them here. Also let me know if this tutorial is useful by using the poll at the top of this page. Thanks!