I'm just developing a Flex mobile application and need to show the upload progress of an image.
The code is:
protected function upload( ba:ByteArray, fileName:String = null ):void {
if( fileName == null ) {
var now:Date = new Date();
fileName = "IMG" + now.fullYear + now.month +now.day +
now.hours + now.minutes + now.seconds + ".jpg";
}
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
var wrapper:URLRequestWrapper = new URLRequestWrapper(ba, fileName, null, params);
wrapper.url = "http://www.the_url_to_upload.com/php_content/upload_image.php";
loader.addEventListener( Event.COMPLETE, completeImageHandler );
loader.addEventListener( ProgressEvent.PROGRESS, imageProgress);
loader.addEventListener(IOErrorEvent.IO_ERROR, errorImageUploading );
loader.load(wrapper.request);
}
private function imageProgress(evt:ProgressEvent):void {
var pcent:Number=Math.floor(evt.bytesLoaded/evt.bytesTotal*100);
label_upload.text = pcent+"%";
}
I have a Label called "label_upload" that should show the percentage of the progress when the file upload.
The fact is that all works fine but the progress event that do not change anything. Always show 0%.
I can not guess my fault.
Thanks.