我敢肯定,这是一件非常容易的事情,但我无法在谷歌找到它几个小时。 我是新来的ActionScript,我试图从一个.php文件生成的字符串中获取一个变量数组。如何从URL编码字符串获取数组?
我的PHP文件输出这样的:
var1=42&var2=6&var3=string
我的ActionScript代码:
public function CallAjax_VARIABLES(url:String , the_array:Array)
{
var request:URLRequest = new URLRequest(url);
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event.COMPLETE, VARIABLES_Complete_Handler(the_array));
try
{
variables.load(request);
}
catch (error:Error)
{
trace("Unable to load URL: " + error);
}
}
function VARIABLES_Complete_Handler(the_array:Array):Function {
return function(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
//the_array = loader.data; // this doesn't work.
//the_array = URLVariables.decode(loader); // this doesn't work either.
//trace(loader.data['var1']); // this outputs 42, so I'm getting the string from php.
};
}
我想你已经明白这一点,但在最后,我想有一个数组(在ActionScript)将给我:
the_array['var1']=42;
the_array['var2']=6;
the_array['var3']="string";
我究竟做错了什么?我该怎么办? 谢谢!
编辑: 我想从PHP获取变量到ActionScript。 例如我的PHP文件正确地将数组转换为html查询,但我不知道如何在ActionScript中将它们解析为数组。
我的回复对你有帮助吗? – silkfire 2013-05-08 16:48:13