Highlighted

FileStream openAsync throws Error #1009

Explorer ,
Feb 22, 2017

Copy link to clipboard

Copied

Hi AIR devs.

Have a problem regarding FileStream openAsync

here my code

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

      }

onComplete returns Error #1009: Cannot access a property or method of a null object reference.

what I am missing? fileStream.open(file, FileMode.READ) works as expected.

"ob" Object is null in your fileReadCompleteHandler function. You need to initialize "ob" Object:
var ob:Object = new Object();

TOPICS
Development

Views

263

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

FileStream openAsync throws Error #1009

Explorer ,
Feb 22, 2017

Copy link to clipboard

Copied

Hi AIR devs.

Have a problem regarding FileStream openAsync

here my code

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

      }

onComplete returns Error #1009: Cannot access a property or method of a null object reference.

what I am missing? fileStream.open(file, FileMode.READ) works as expected.

"ob" Object is null in your fileReadCompleteHandler function. You need to initialize "ob" Object:
var ob:Object = new Object();

TOPICS
Development

Views

264

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 22, 2017 0
Engaged ,
Feb 22, 2017

Copy link to clipboard

Copied

"ob" Object is null in your fileReadCompleteHandler function. You need to initialize "ob" Object:
var ob:Object = new Object();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 22, 2017 1
Explorer ,
Feb 23, 2017

Copy link to clipboard

Copied

itlancer​ you are right, this was my mistake

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2017 0