【问题标题】:FileStream openAsync() throws SecurityErrorFileStream openAsync() 抛出 SecurityError
【发布时间】:2013-03-05 14:09:53
【问题描述】:

这是我的代码:

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()

谁能帮帮我?

【问题讨论】:

    标签: flash actionscript-3 air


    【解决方案1】:

    问题已解决:applicationDirectory 是只读的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多