mar*_*ocb 2 apache-flex actionscript-3 flex4.5 flex-mobile
我有一个在iPad上运行的Flex应用程序(SDK 4.5.1)...我需要下载任何文件,将它们放在本地目录(如File.applicationStorageDirectory)中,然后查看我的应用程序中的文件.
所以在我的测试应用程序中,使用urlLoader类下载了一个png图像.
这是下载的完整处理程序:
private function onComplete3(event:Event):void{
try{
var ba:ByteArray = event.target.data as ByteArray;
var file:File=File.applicationStorageDirectory.resolvePath("img.png");
var pathFile:String = file.nativePath;
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(ba);
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
status0.text = "STATE : ERROR 3"
});
fileStream.close();
status0.text = "STATO : OK";
path0.text = pathFile;
immagine0.source = pathFile;
catch(e:Error){
status0.text = "STATE : ERROR 2"
}
}
Run Code Online (Sandbox Code Playgroud)
在我的iPad上,我可以看到下载的文件存在,但是当我运行immagine0.source = pathFile(这是一个图像组件)时,没有任何东西出现......也许我可以写一个文件,但我看不懂它?
经过6个小时的调试和编码......我用一个非常简单的解决方案解决了这个问题...改变了这条线
var pathFile:String = file.nativePath;
Run Code Online (Sandbox Code Playgroud)
同
var pathFile:String = file.url;
Run Code Online (Sandbox Code Playgroud)
他用这种方式解决了file.url:
app-storage:/img.png
Run Code Online (Sandbox Code Playgroud)
它现在有效!希望这篇文章对其他有此问题的人有所帮助.谢谢所有人