It was nice enough in AS2 when you did a simple LoadVars object to get the data from a server side page :
var lv:LoadVars = new LoadVars();
lv.username = "ruliman";
lv.password = "123456";
lv.sendAndLoad("somefile.php",lv,"POST");
All I had to do is print on my php something like:
&message=something&var1=somethingelse&
where I was starting with & and ending with & , using name value pairs.
it Was simple , straight forward and everybody got used to it, from Flash designers to php programmers.
In AS3 though things are different.
var variables:URLVariables = new URLVariables();
variables.username = "ruliman";
variables.password= "123456";
//
trace(variables.toString());
var request:URLRequest = new URLRequest("somefile.php");
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
try{
loader.load(request);
}
catch (error:Error) {
trace("Unable to load URL");
}
First you need to STOP starting and ending with &.
You dont need that and in fact , you will get the above error, leaving you wondering why on earth this is not working
so from AS2 where in php you printed
print "&message=something&var1=somethingelse&";now you need to print
print "message=".urlencode(something)."&var1=".urlencode(somethingelse);
so you loose the & in the beginning and in the end plus you make sure all returned data (apart from variables names) are urlencoded.
Adobe should at least MAKE A DAMN NOTE on this new way of handling the returned data from a url posted page...
Related posts:
- Image upload with AS3 mac problem fix I hit my head several times on the wall before...
- flash to become crawlable Επιτέλους η Macromedia θα συτεργαστεί με την google και την...







Sun, May 9, 2010
Programming