我有一个应用程序正在下载几个大型二进制文件并将它们保存到磁盘。在某些机器上它工作正常,在其他一些机器上,每隔一段时间下载将进行99.9%完成并且URLStream对象不会触发Event.COMPLETE
这几乎与此处出现的问题相同:
Why does URLStream complete event get dispatched when the file is not finished loading?
我尝试过使用其中一个答案中描述的“Cache Bust”方法,但仍然没有骰子。
任何帮助将不胜感激。
以下是一些示例代码,以帮助说明我要做的事情:
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 );
答案 0 :(得分:0)
我从未注册过所有可用的错误事件(您不会注册任何错误事件)。
我从不使用匿名听众。即使它们在下载完成之前不应该是GC,这也是一个不必要的不安全的赌注,特别是因为URLStream在加载最后一位时稍微空闲一点并不罕见。如果删除那些匿名听众会真正解决问题,我不会感到惊讶。