是否可以下载并使用Adobe AIR的保存文件? [英] Is it possible to download and save file using adobe air?

查看:224
本文介绍了是否可以下载并使用Adobe AIR的保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我犯了一个闪光的AIR应用程序为Android,我需要下载文件并保存到本地应用程序目录

i made a flash air application for android and i need to download file and save to application local directory

在此先感谢....

推荐答案

的URLRequest和URLLoader将允许您来从互联网的一些数据文件流让你,如果你想让他们选择在哪里保存它保存到本地(的FileReference )在

URLRequest and URLLoader will allow you to fetch some data from the internet, FileStream allows you to save it locally (FileReference if you want them to choose where to save it) as in

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                var urlLoader:URLLoader = new URLLoader();
                urlLoader.addEventListener(Event.COMPLETE, complete_handler);
                urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                urlLoader.load(new URLRequest("http://www.shaunhusain.com/CheckboxList/CheckboxList.swf"));

            }

            private function complete_handler(event:Event):void
            {
                var data:ByteArray = event.target.data;

                var fr:FileReference = new FileReference();
                fr.save(data, 'test.swf');

                var fileStream:FileStream = new FileStream();
                trace(File.applicationDirectory.nativePath);
                fileStream.open(new File(File.applicationDirectory.nativePath+"\\test.swf"),FileMode.WRITE);
                fileStream.writeBytes(data, 0, data.length);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:WindowedApplication>

编辑: AS3移动项目版本:

AS3 Mobile project version:

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    import flash.net.FileReference;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;

    public class DownloadFileMobileAS3 extends Sprite
    {
        public function DownloadFileMobileAS3()
        {
            super();

            // support autoOrients
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            createLoader();
        }
        protected function createLoader():void
        {
            // TODO Auto-generated method stub
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, complete_handler);
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.load(new URLRequest("http://www.shaunhusain.com/CheckboxList/CheckboxList.swf"));

        }

        private function complete_handler(event:Event):void
        {
            var data:ByteArray = event.target.data;

            var fr:FileReference = new FileReference();
            fr.save(data, 'test.swf');

            var fileStream:FileStream = new FileStream();
            trace("something");
            trace(File.applicationDirectory);
            trace(File.applicationDirectory.nativePath);
            trace(File.applicationStorageDirectory.nativePath);
            fileStream.open(new File(File.applicationStorageDirectory.nativePath+"\\test.swf"),FileMode.WRITE);
            fileStream.writeBytes(data, 0, data.length);
        }
    }
}

我包含在code两个选项上面,你会想要么拿出文件引用的部分或取出文件流的一部分,否则它会被保存两次。

I included both options in the code above you would want to either take out the file reference part or take out the file stream part otherwise it'll be saved twice.

我刚刚加入的移动部分,它实际上确实有某种形式的对话框中,它会提示您保存在Android上的文件,虽然这是一个对话框,我从来没有见过的,只是给你在哪里保存选项它和音频文件,图像文件和视频文件的选项,或在/mnt/sdcard/test.swf默认位置。我让它保存那里,我能够用ES浏览器看到它(虽然我有没有什么好办法来验证是在机智它通常看起来是正确的数据)。使用applicationDirectory的一人没有在我身上,追查出来,我看到没有nativePath的,所以我切换到applicationStorageDirectory其中有一个价值,它似乎已经得救,没有错误,不幸的是它在我的根/数据文件夹,因为我不要'吨有我的手机植根我也没办法完全确认文件实际上是有,但没有错误。让我知道如果你已经尝试这样做,有什么具体的问题,你仍然遇到。

I just added the mobile section, it in fact does have some sort of dialog it prompts you with for saving a file on Android, though it's a dialog I've never seen before, just gives you the option of where to save it and Audio Files, Image Files, and Video Files as options or a default location at /mnt/sdcard/test.swf. I let it save there and am able to see it using ES Explorer (though I had no good way to verify the data was in tact it appears generally to be correct). The one using the applicationDirectory was failing on me, tracing it out I was seeing no nativePath so I switched it to applicationStorageDirectory which had a value and it seems to have saved without error, unfortunately it's in my root /data folder and since I don't have my phone rooted I have no way to completely confirm the file is actually there but no errors. Let me know if you've tried this and what specific issues you're still encountering.

这篇关于是否可以下载并使用Adobe AIR的保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆