Skip navigation
Currently Being Moderated

Loader.content always null even after fully loaded

May 25, 2012 7:31 PM

Tags: #problem #air #as3

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?

 
Replies
  • Currently Being Moderated
    May 25, 2012 8:04 PM   in reply to Greek Fellows

    Where are you declaring the loader?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points