FileStream openAsync()抛出SecurityError

时间:2010-06-17 11:51:28

标签: flash actionscript-3 air

这是我的代码:

package com.func
{
    public class Downloader
    {
        import flash.events.*;
        import flash.filesystem.*;
        import flash.net.FileReference;
        import flash.net.URLStream;
        import flash.utils.ByteArray;
        import flash.net.URLRequest;
        import mx.controls.Alert;

        private var req:URLRequest = new URLRequest();
        private var us:URLStream = new URLStream();
        private var fs:FileStream = new FileStream();
        public function Downloader()
        {
        }

        public function download():void{
            var file:File = File.applicationDirectory.resolvePath("quotes.csv");
            req.url = "http://www.domain.com/data.csv";
            us.addEventListener(ProgressEvent.PROGRESS, writeFile);
            us.addEventListener(Event.COMPLETE, loaded);
            fs.openAsync(file, FileMode.WRITE);
            us.load(req);
        }

        public function writeFile(event:Event):void{
            var data:ByteArray = new ByteArray();
            us.readBytes(data, 0, us.bytesAvailable);
            fs.writeBytes(data, 0, data.length);
        }

        public function loaded(event:Event):void{
            var data:ByteArray = new ByteArray();
            us.readBytes(data, 0, us.bytesAvailable);
            fs.writeBytes(data, 0, data.length);
            fs.close();
        }
    }
}

当我执行并启动该功能时,它总是会导致错误。错误讯息:

SecurityError: fileWriteResource
    at runtime::SecurityManager$/checkPrivilegeForCaller()
    at flash.filesystem::FileStream/openAsync()

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

问题已解决:applicationDirectory为只读。