本文介绍了的URLLoader加载多文件和结果顺序是相同的呼叫负载()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于的URLLoader是异步,如何确保从服务器端数据的顺序是一样的于Loader.load()调用?换句话说,在totalResults数据顺序是链接相关的内容的顺序相同?

以下是code片断:

  1.适用于每一个(VAR URL中的URL){
    loadData(URL);
}
2.private功能loadData(网址:字符串):无效{
    VAR的URLLoader:的URLLoader =新的URLLoader();
    urlLoader.addEventListener(引发Event.COMPLETE,在completeHandler);
    VAR要求:的URLRequest =新的URLRequest(URL);
    对URLLoader.load(要求);
}
3.private功能在completeHandler(事件:事件):无效{
    VAR装载机:的URLLoader =的URLLoader(将event.target);
    VAR结果:对象= loader.data;
    totalResults.push(结果); //假设totalResults是阵列和类中的属性。
}
 

解决方案

您可以扩展的URLLoader 类的功能。

 动态类DynamicURLLoader扩展的URLLoader {}
 

然后将其存储的数据(在你的情况可能是首页)的Loader对象,要求前:

  VAR的URLLoader:DynamicURLLoader =新DynamicURLLoader();
 urlLoader.index = ...
 

响应后,检索数据(在你的案件首页):

  VAR装载机:DynamicURLLoader = DynamicURLLoader(将event.target);
totalResults [loader.index] = loader.data;
 

Since URLLoader is async, how to make sure the order of data from server side is the same as the loader.load() call? In other words, the data order in totalResults is the same order of url-related content?

Following is code snippet:

1.for each(var url in urls) {
    loadData(url);
}
2.private function loadData(url:String):void {
    var urlLoader:URLLoader = new URLLoader();
    urlLoader.addEventListener(Event.COMPLETE, completeHandler);
    var request:URLRequest = new URLRequest(url);
    urlLoader.load(request);
}
3.private function completeHandler(event:Event):void {
    var loader:URLLoader = URLLoader(event.target);
    var result:Object = loader.data;
    totalResults.push(result);// suppose totalResults is Array and a property in the class.
}
解决方案

You can extend URLLoader class functionality.

dynamic class DynamicURLLoader extends URLLoader { }

Then store data ( in your case probably index ) in loader object, before requesting:

 var urlLoader:DynamicURLLoader  = new DynamicURLLoader();
 urlLoader.index = ...

After response, retrieve that data ( in your case index ):

var loader:DynamicURLLoader = DynamicURLLoader(event.target);
totalResults[ loader.index ] = loader.data;

这篇关于的URLLoader加载多文件和结果顺序是相同的呼叫负载()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 18:43