在 iPad Flex4.5 应用程序中从 File.applicationStorageDirectory 保存/读取文件
我有一个在 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"
}
}
在我的 iPad 上,我可以看到下载的文件存在,但是当我运行 immagine0.source = pathFile (这是一个图像组件)行时,什么也没有出现......也许我可以写一个文件,但我无法读取它?
I have a Flex application (SDK 4.5.1) which runs on iPad... I need to download any files, put them in local directory (like the File.applicationStorageDirectory) and then view the file inside my application.
So in my test application a downloaded a png image using the urlLoader class.
Here it is the complete handler of the download:
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"
}
}
On my iPad I can see the downloaded file exists, but when I run the line immagine0.source = pathFile (which is an image component), nothing appears... Maybe I can write a file but I cannot read it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过 6 个小时的调试和编码...我用一个非常简单的解决方案解决了这个问题...
更改了行
,
他以这种方式解决了 file.url:
。现在可以了!希望这篇文章对其他人有这个问题有帮助。谢谢大家
After 6 hours of debug and coding...i solved this problem with a very simple solution...
changed the line
with
He solved the file.url in this way:
.Now it works! Hope this post will be helpful for someone other have this problem..Thanks to all
以下两个函数是在Flex 4.5中写入和读取文件。
The following 2 functions are to write and read file in Flex 4.5.