Using URLVariables()

By | September 18, 2014

URLVariables Class allow you to send or receive data from an URL encoded feed (with the data property of the URLRequest class).
There is so two possible use:

  1. Sending parameters to a server side script
  2. Read parameters written from a server side script

The use is quite simple, let’s start by building the PHP file that will receive the variables from a POST method and echo them again with a list of parameters association by name and value: email=”..”&id=”..”&db=”…”.

< ?php

 echo "email=".$psPreRegEmail;
 echo "&id=".$FRM_ID;
 echo "&db=".$psBD;

Now we need to prepare our AS3 script that will send this 3 variables to our PHP file:

var request:URLRequest = new URLRequest("");
var variables:URLVariables = new URLVariables();//create a variable container
variables.sEml = email;
variables.sID = theForum;
variables.sBD = theDB; = variables;//add the data to our containers
request.method = URLRequestMethod.POST;//select the method as post
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.load(request);//send the request with URLLoader()


Here we send the variables and wait for the Event.COMPLETE, it will indicates us that the php files is totally downloaded (and so all the scripts has been executed). Now we can prepare our HandleComplete function:

function handleComplete(event:Event)
var loader:URLLoader = URLLoader(;
var vars:URLVariables = new URLVariables(;
//Access data from the PHP file
trace(" ";
trace(" ";
trace("vars.db: "+vars.db);

That’s all!


1 Kudos

2 thoughts on “Using URLVariables()

  1. Kitsu


    I tried your example but instead of having the correct values with trace, I get the php code itself.
    That means I get: “.$FRM_ID;
    echo “vars.db: “.$psBD;

    I know it comes from the php configuration on my server because I tested it on another server and it works, but I can’t find what I must change in my php.ini file to get the good results in trace();
    Do you have any idea? thanks

  2. Marcel Doornbos


    I’m trying out Adobe AIR. and since there can’t be a database connection directly from there. I thought this could be something that could work. But.. I can’t seem to find out how to get this script working.

    Could you tell me how this script should look like in a HTML file? like with a form to create the variables that will be send to the server php file.(You can e-mail me at the e-mail which I put at mail in this comment)

    I hope you reply soon,

    Marcel Doornbos