Hello and welcome to another quick AS3 tutorial. As with any client-side application, eventually you’ll want to comunicate with a server, for instance to display scores and such. This is something that Flash has been able to do quite a few versions back, but some of you may not know what the AS3 equivalent is. So Here we go.
In AS3 we use the URLVariables class to store our intended variables like so:
first we instantiate the myVariables var with the URLVariables class.
var myVariables:URLVariables = new URLVariables();
Then we create and define properties within the myVariables instance (these are the names we will call in PHP to access the data).
myVariables.myName = "Bill"; myVariables.beans = "beans are awesome!";
We now have to create an instance of the URLRequest class in order to send our variables.
var myURLRequest:URLRequest = new URLRequest("http://www.mywebsite.com/phpvarstutorial.php");
Now for the magic that makes it all work…
myURLRequest.data = myVariables; navigateToURL(myURLRequest, '_blank');
Basically what we are doing there is attaching our URLVariables to our URLRequest as data to be transmitted along to the target URL. And then using the navigateToURL function to send everything (and also bring up the page).
You can then use $_GET['var']; in PHP to retrieve the variables.
See our PHP Basics : Get Command – Using URL Queries & Variables tutorial to learn how to read the passed variables.
Example files here (PHP included):
Thanks for reading
Bill




