FileStream openAsync 抛出错误 #1009

FileStream openAsync throws Error #1009

嗨,我有一个关于 FileStream openAsync 读取文件的问题,我有一个侦听器并正在等待完成

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

      }

在 fileReadCompleteHandler 上出现错误:"Error #1009: Cannot access a property or method of a null object reference." 我缺少什么,如何从 openAsync 读取对象?

谢谢

您永远不会初始化对象 ob,当然访问空对象的字段会给您 #1009:

    var ob:Object;
    var fileStream:FileStream = FileStream(event.currentTarget);

    try {
        ob.source = fileStream.readObject();

您需要:

    var ob:Object = new Object;
    var fileStream:FileStream = FileStream(event.currentTarget);

    try {
        ob.source = fileStream.readObject();