Loader.content always null even after fully loaded
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?