1 Reply Latest reply on Dec 14, 2010 4:54 PM by Joe ... Ward

    asynchronous WRITE not always working

    Kaspar V Level 1

      I have these functions to perform xml file writing to the disk in an AIR app.
      The problem is that about half the times it seems that the file is not written on the disk, OutputProgressEvent is not fired.
      Is it possible because of the small data size?

       

       

      public function saveXML(xml:XML):void{
                  trace("starting save") // always firing
                  var fs:FileStream = new FileStream();
                  fs.addEventListener(Event.CLOSE, _closeHandler);
                  fs.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, _outputProgressHandler)
                  fs.openAsync(library, FileMode.WRITE);
                  var xmlData:String = '<?xml version="1.0" encoding="utf-8"?>' +xml;
                  trace("xml "+xmlData) // always firing, shows that data exists
                  fs.writeUTFBytes(xmlData);
                  trace("write started") // always firing
              }
              private function _outputProgressHandler(evt:OutputProgressEvent):void{
                  trace("progress? "+evt.bytesPending) // sometimes not firing
                  if(evt.bytesPending==0){
                      trace("no bytes") // sometimes not firing
                      evt.target.close();
                  }
              }
              private function _closeHandler(evt:Event):void{
                  trace("filestream close, file saved") // sometimes not firing
              }