FileStream openAsync() выдает SecurityError

Вот мой код:

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

Может кто-нибудь помочь мне?


person rie    schedule 17.06.2010    source источник


Ответы (1)


Проблема решена: applicationDirectory доступен только для чтения.

person rie    schedule 17.06.2010