多个 URLLoader
我正在使用 URLLoader 加载多个 xml 文件。
for (var i=0;i<xmlCount;i++) {
loadXML(xmlFiles[i], i);
}
public function loadXML(req:String=null, _id:Number=0):void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(ProgressEvent.PROGRESS,
function a(e:ProgressEvent) {XMLLoadProgress(e, _id);});
loader.addEventListener(Event.COMPLETE, XMLLoadFinished);
loader.load(new URLRequest(req));
}
private function XMLLoadProgress(e:ProgressEvent=null, _id:Number=0):void {
dispatchEvent(new LoadingEvent(Model.LOADING_PROGRESS, _id, (e.bytesLoaded/e.bytesTotal)*100));
}
问题是我认为 LOADING_PROGRESS 在所有加载完成后被调度,并且每个 xml 都被一一加载,而不是异步加载。
我怎样才能使其异步加载,并使其为每个进度标记调用进度事件。
I am loading multiple xml files with URLLoader.
for (var i=0;i<xmlCount;i++) {
loadXML(xmlFiles[i], i);
}
public function loadXML(req:String=null, _id:Number=0):void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(ProgressEvent.PROGRESS,
function a(e:ProgressEvent) {XMLLoadProgress(e, _id);});
loader.addEventListener(Event.COMPLETE, XMLLoadFinished);
loader.load(new URLRequest(req));
}
private function XMLLoadProgress(e:ProgressEvent=null, _id:Number=0):void {
dispatchEvent(new LoadingEvent(Model.LOADING_PROGRESS, _id, (e.bytesLoaded/e.bytesTotal)*100));
}
The problem is I think LOADING_PROGRESS gets dispatched after all the loading is done and each xml is loaded one by one not asynchronously.
How could I make it load asynchronously and also make it so progress event is called for each progress tick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜这只在通过快速连接查看时才会发生。尝试使用慢速连接查看(Charles Proxy 能够人为地减慢您的连接速度)。
I'm guessing this only happens when viewing over a fast connection. Try viewing with a slow connection (Charles Proxy has the ability to artificially slow down your connection).
您可以自定义 URLLoader。
然后在每个 loadXML 中,标记加载器:
You can customize the URLLoader.
then in each loadXML, mark the loader: