Martin Laing - Multimedia Developer | Fife, Scotland

How to send data from Flash to PHP

How to send data from Flash to PHP

This tutorial aims to show you how to send data from flash to php, useful situations for this are high score systems on games and such things.

This Tutorial requires you to have a basic knowledge of both php and flash although the method is relatively simple.

Step1 - Setting up the Flash file

First of all you must create the flash part of the system.

First things first go to the frame where the "GAME OVER" part is displayed along with the final score which is to be sent to a php file.

You will then need to create a Button on the frame, a simple rectangular box with submit written on it should do, but you can go for something more fancy if you want.

Once this is created go back to the "GAME OVER" frame and give the button an Instance Name of submit_btn this is important as we will need to refer to the button using this name in the code.

Next click on the frame where the "GAME OVER" screen is displayed and open the Actions panel (F9) Then make sure the frame is stopped by including the following code at the top of the actions window:

stop();

Next we will want to setup the button properties so include the following code on the same page:

submit_btn.onRelease=function() {

loadVariablesNum("submitscore.php", "_blank", "POST");   

}



The above code basically says When submit_btn is Released send variables to submitscore.php using a blank browser window and form method POST.

Thats all that needs to be done on the flash side, so let of a sigh of relief (Pheww..) Not that hard was it...

Now on to the php part of the system.

Step2 - Setting up the PHP file

Create a blank php file and save it as submitscore.php

Next thing you want to do is to create the code which is going to receive the variables from flash so we simply ask for them using a $_POST request.

<?php

$score=$_POST['score'];

?>



Remember to substitute score with whatever you want to call your php variable and score with whatever your score variable was set to in the flash file or the system will fail.

After that you can simply do whatever you want with the new variable you have in the php file, but remember to let the user know what is going on by echoing a reponse to them when you are finished what you are doing with the variable.

For example you may want to add it to the database so once you check the sql query was successfully you can echo a message to let them know the score has been added to the database successfully.

If you just want to display their score to them then you can simply echo their score to them.

Remember you can style the page as you normally would just remember to include the code part in the main section so the echo's are echoed in the content area of the page.

That pretty much concludes this tutorial, there are many more things to flash and php for example sending things back to flash, but that will be covered in a future tutorial.

If you have any trouble with the tutorial or want further help with setting up flash to work with php use the Contact Me page to send me a message.

Comments

Comments will be displayed here

Back to Tutorial Home

Latest Projects

Fallen Angels Website Development Bucketball Candy Drop Fallen Angels Bebo Application Hector the Inspector

View Full Portfolio


Contact Me

If you would like to contact me, the easiest and quickest way to do so is by filling out the contact form on this website.

Send Me a Message

If you prefer you can contact me on any of these Websites:


Bebo facebook Myspace Twitter

Tutorials


How to send data from Flash to PHP How to create a Contact Form using PHP How to create simple Member Login for your websites. Part 1 - Member Login How to create simple Member Login for your websites. Part 2 - Session Management How to create simple Member Login for your websites. Part 3 - Logging Out Users