mercredi 22 février 2017

FileStream openAsync throws Error #1009

hi I have a problem regarding FileStream openAsync read file, I have a listener and waiting on complete

    var file:File = File.applicationStorageDirectory.resolvePath(fName+'.'+EXT);
    var fileStream:FileStream = new FileStream();  


     if (!file.exists) {
              this.dispatchEvent(new AppEvent(AppEvent.DATA, null, false));                                         

     }else {

         fileStream.addEventListener(Event.COMPLETE, fileReadCompleteHandler);
         fileStream.openAsync(file, FileMode.READ);
         fileStream.addEventListener(Event.CLOSE, fileClosedHandler);
         fileStream.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler);
     }


     private function fileReadCompleteHandler(event:Event):void {
        var ob:Object;
        var fileStream:FileStream = FileStream(event.currentTarget);

        try {
            ob.source = fileStream.readObject();
        }catch (e:Error) {
            trace('error:' + e.message) 
        }

        fileStream.removeEventListener(Event.COMPLETE, fileReadCompleteHandler);
        fileStream.close(); 

      }

on fileReadCompleteHandler I get error: "Error #1009: Cannot access a property or method of a null object reference." what I am missing, how can I read object from openAsync?

thanks

Aucun commentaire:

Enregistrer un commentaire