When communicating with server via GET to a php script, I need a feedback, usually in the format: status=OK&msg=No further actions&other=blablabla … so I know that was a successfull request. But AS3 is very object-oriented, so I made a Class to put it in an object:
package com.gustavopi.comm {
public class Vars {
public var demo:String = new String();
public var Obj:Object = new Object();
public var Var:Array = new Array();
public var Val:Array = new Array();
public function Vars(strVars:String=null) {
var Termos:Array = strVars.split("&");
for(var t in Termos){
var termo:String = Termos[t];
var Elem:Array = termo.split("=");
Obj[Elem[0]] = Elem[1];
Var.push(Elem[0]);
Val.push(Elem[1]);
demo += Elem[0]+": "+Elem[1]+String.fromCharCode(13);
}
}
}
}
The advantage is quickly detect errors using “demo” method, but the vars are properties of Obj, not of the object itself, wich is a little strange – but works.
I’m not sure if this is the best way to deal with the task or if I did something that already exists in the AS3 core. What do you think about?
First, your variables should start with a lower case whereas the classes start with an upper case.
There are several ways to get some data from a server, yours is the simplest and oldest one. It was commonly used with AS2. That is exactly why there is already a class to handle this:
Check out the AS3 URLVariables class.