无论如何,是否可以使用 URLLoader 下载文件,然后将其保存到磁盘而不使用文件引用或任何使用对话框的内容?这是我拥有但不起作用的:
public function onDownloadComplete(e:Event):void
{
DownloaderProgress.label = 'Download Done';
var loader:URLLoader = URLLoader(e.target);
var rtsFile:File = File.applicationStorageDirectory.resolvePath("RTS.zip");
var rtsStream:FileStream = new FileStream();
rtsStream.open(rtsFile, FileMode.WRITE);
rtsStream.writeBytes(loader.data);
rtsStream.close();
}
另请澄清,我的程序位于 adobe air 中。因此它将作为桌面应用程序运行,而不是网页上的 Flash 对象。
您必须使用 URLStream 而不是 URLLoader:
var downloadStream:URLStream = new URLStream();
downloadStream.addEventListener(Event.COMPLETE, onDownloadComplete);
downloadStream.load(new URLRequest(url));
// ...
private function onDownloadComplete(event:Event):void
{
var bytes:ByteArray = new ByteArray();
downloadStream.readBytes(bytes);
try
{
// delete old file first
if (_saveToFile.exists)
{
_saveToFile.deleteFile();
}
_fs = new FileStream();
_fs.addEventListener(IOErrorEvent.IO_ERROR, onSaveFileIOError);
_fs.open(_saveToFile, FileMode.WRITE);
_fs.writeBytes(bytes);
_fs.close();
_fs.removeEventListener(IOErrorEvent.IO_ERROR, onSaveFileIOError);
}
catch (error:Error)
{
trace("could not write file to local machine");
}
}
我只是从我的班级中复制并粘贴了一些代码。不是 100% 完成,但应该为你指明正确的方向......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)