php - 这个 URLRequest 或 Loader 有什么问题?

标签 php mysql apache-flex actionscript-3 flash-builder

我有以下代码:

var myRequest:URLRequest = new URLRequest("http://localhost/example.com/scripts/get_peerID.php?peerID=" + myID.text);
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = "URLLoaderDataFormat.VARIABLES";
myLoader.load(myRequest);
writeText(myLoader.data);
var vars:URLVariables = new URLVariables(myLoader.data);
writeText(vars.peerID);

get_peerID.php? 获取显示:

peerID=5a00d01af308bb4261198d92a89b939979e7ea260a3ead7d49a9b6bdd0492b72

但是,writeText(vars.peerID) 总是显示null。我似乎无法弄清楚为什么。有什么想法吗?

最佳答案

URLLoader类是异步的。引用文档:

A URLLoader object downloads all of the data from a URL before making it available to code in the applications. It sends out notifications about the progress of the download, which you can monitor through the bytesLoaded and bytesTotal properties, as well as through dispatched events.

因此,vars.peerID 在调用 URLLoader.load 方法后直接工作的唯一方法是您的网络延迟为零并且服务器端处理的执行时间为 0。两者都极不可能。

相反你应该听complete事件。

var myRequest:URLRequest = new URLRequest("http://localhost/example.com/scripts/get_peerID.php?peerID=" + myID.text);
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = "URLLoaderDataFormat.VARIABLES";
myLoader.addEventListener(Event.COMPLETE,onComplete);
myLoader.load(myRequest);

然后在代码后面的某处,像这样:

public function onComplete(event:Event):void{
 writeText(myLoader.data);
 var vars:URLVariables = new URLVariables(myLoader.data);
 writeText(vars.peerID);
}

关于php - 这个 URLRequest 或 Loader 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5845202/

相关文章:

php - 如何在冗长的数组上执行多个 array_slice?

php - 如何从一个MySQL表中获取数据并同时输入到另一个表中

arrays - ArrayCollection 扩展错误

flash - 使用 SampleDataEvent 为 NetStream 中的音频实时修改声音

apache-flex - 如何在 flex 中的 Canvas 组件周围创建类似 float 效果的阴影?

php - 何时可以在多维数组中访问定义的变量?

javascript - 单击复选框然后使用 jquery 删除验证

php - urlencode 除外/

php - 优化 mysql 数据库 - 任务列表耗尽了我的服务器

mysql - 如何以mysql中给定的格式获取mysql中的当前日期-1?