Skip to main content
Known Participant
May 26, 2012
Question

Loader.content always null even after fully loaded

  • May 26, 2012
  • 1 reply
  • 752 views

I'm making an image loader, using File.browseForOpen to get the url, then load it with the Loader.

Then I added an event listener to its contentLoaderInfo that listens to ProgressEvent.PROGRESS

The code is like this:

private function progress(pe:ProgressEvent):void {

                              if (pe.bytesLoaded >= pe.bytesTotal) {

                                        this.message = text("Upload succeed.", 400, 100, 24);

 

                                        if (this.loader.content.width > 800 || this.loader.content.height > 600) {

                                                  this.removeChild(this.loader);

 

                                                  this.message = text("The image size should not exceed 800*600 pixels. Please upload another.", 400, 100, 24);

                                        }

 

                                        this.removeEventListener(ProgressEvent.PROGRESS, progress);

                              } else {

                                        this.message = text("Uploading " + pe.bytesLoaded + " bytes of " + pe.bytesTotal + "bytes. "+pe.bytesLoaded/pe.bytesTotal*100+"percent complete.", 400, 100, 24);

                              }

                    }

But it gives an error:

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

and when I check the local variables, this.loader.content seems to be null, even after bytesLoaded is equal or larger than bytesTotal.

Is there a solution?

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 26, 2012

Where are you declaring the loader?

Known Participant
May 26, 2012

this.loader = new Loader();

                              this.loader.load(url);

                              this.addChild(this.loader);

 

                              this.loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);

url is an URLRequest.