首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么URLStream有时不解雇Event.COMPLETE?

为什么URLStream有时不解雇Event.COMPLETE?
EN

Stack Overflow用户
提问于 2016-04-13 01:42:16
回答 1查看 106关注 0票数 0

我有一个应用程序,它下载几个大的二进制文件并将它们保存到磁盘上。在某些机器上,它工作得很好,而在其他一些机器上,每隔一段时间,下载就会完成99.9%,并且URLStream对象不会触发Event.COMPLETE

这与此处出现的问题几乎完全相同:

Why does URLStream complete event get dispatched when the file is not finished loading?

我试过使用其中一个答案中描述的“Cache Bust”方法,但仍然没有结果。

任何帮助都将不胜感激。

下面是一些示例代码来帮助说明我正在尝试做的事情:

代码语言:javascript
复制
var contentURL:String = "http://some-large-binary-file-in-amazon-s3.tar";

var stream:URLStream = new URLStream();
stream.addEventListener(Event.COMPLETE, function(e:Event):void{
    //This should fire when the file is done downloading
    //On some systems this fails to fire once in a while
    //On other systems it never fails to fire               
});
stream.addEventListener(ProgressEvent.PROGRESS, function(pe:ProgressEvent):void{
    //Write the bytes available in the stream and save them to disk
   //Note that a download will reach 100% complete in terms of total progress but the 'complete' event might still not fire.
});

var urlRequest:URLRequest = new URLRequest(contentURL);
//Here we might add some headers to the URL Request for resuming a file
//but they don't matter, the 'Event.COMPLETE' will fail to fire with our without
//these headers
addCustomHeaders( urlRequest );

stream.load( urlRequest );
EN

回答 1

Stack Overflow用户

发布于 2016-04-15 21:50:33

Imo,这是一个注定要失败的代码,你故意放弃对正在发生的任何事情的控制,只是假设一切都会自己工作并运行良好。我在使用URLStream类时从来没有遇到过任何问题,但以下是我基本上从不做的事情:

  1. 我从不不注册所有可用的不同错误事件(您不需要注册任何错误事件)。
  2. 我从不使用匿名侦听器。即使它们应该在下载完成之前不是GC,但这是一个不必要的不安全的赌注,特别是因为在加载最后一位时URLStream空闲一点的情况并不少见。如果删除这些匿名侦听器真的能解决这个问题,我一点也不会感到惊讶。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36580439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档