Flex Air移动文件下载



我正在构建一个Adobe Air Mobile应用程序,目前目标是Android(最终是iOS)。我使用的是FlashBuilder4.6(即Flex)。

我需要从url下载一个zip文件,将其保存到本地存储并解压缩内容。

关于如何在Flex/Air中进行下载,似乎有一些例子,但在Flex/Air/Mobile中却不多。此外,示例的混合似乎到处都是命名空间版本等。

有人能提供一个简洁的例子,说明如何在Air Mobile应用程序中做到这一点吗?

谢谢!

编辑:我尝试过的:

因此,从网络上的例子来看,我做的第一件事就是在Flex声明中添加名称空间:xmlns:net="flash.net.*"

然后我添加了以下组件:<net:URLLoader id="urlLoader" />

然后,在按钮点击事件中,我称之为:urlLoader.load(new URLRequest(downloadUrl));

我得到一个运行时错误:Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://。。。

问题是,我不知道从这里去哪里,因为我不确定缺少了什么。

此代码适用于IOS:

public function download():void{
        var loader:URLLoader = new URLLoader();
        loader.dataFormat = URLLoaderDataFormat.BINARY;
        loader.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
            Alert.show('error IO');
        });
        loader.addEventListener(Event.COMPLETE,downloadComplete);
        loader.load(new URLRequest(YOUR_URL));          
    }
private function downloadComplete(event:Event):void{
        try{
            var file:File=File.applicationStorageDirectory.resolvePath(YOUR_LOCAL_PATH);
            var ba:ByteArray  = event.target.data as ByteArray;
            var fileStream:FileStream = new FileStream();
            fileStream.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
                Alert.show('error IO');
            });
            fileStream.open(file, FileMode.WRITE);  
            fileStream.writeBytes(ba);  
            fileStream.addEventListener(Event.CLOSE, fileClosed);  
            fileStream.close(); 
            Alert.show("File downloaded succesfully")   
        }
        catch(eeee){
            Alert.show("error")
        }
    }

最新更新