2010-06-17 4 views
1

Вот мой код: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() 

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

ответ

3

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

Смежные вопросы