November 20, 2011 in Actionscript, PHP, Programming, Tutorials by admin

Have you ever wanted to post variables from AS3 to a PHP and get data back from the PHP? This tutorial will show you how to easily take ActionScript 3 variables and post the to PHP. We will create a simple login with AS3 and PHP.

In our ActionScript we will be using urlRequest and URLLoader to send data to a PHP file and retrieve information back into the ActionScript.

In our urlRequest we will first determine the location of our PHP file and then set any variables that we want to send to the PHP. We will add all of our variables to a URLVariables() object and add that to our urlRequest.

We then add our request to the loader and add an event listener to fire on completion. There we will grab our variables that were sent from our PHP file.

In our PHP file we can grab our variables and handle them in PHP. This makes it easy to create sessions and store in the database. Using GET parameters we can return variables back to our ActionScript file.

Save this as your login.php

» Download – Source Files for this tutorial


Included Files

  • Main.fla – The main project file for the demo
  • Main.as – The main ActionScript file for the demo
  • login.php – PHP file to handle posted AS3 variables
  • Main.html – HTML to view published swf
  • Main.swf – Published swf movie file
  • ReadMe.txt – Tutorial demo instructions