开发者

Actionscript-3 URLLoader: ProgressEvent doesn't dispatch

开发者 https://www.devze.com 2023-01-27 08:05 出处:网络
I upload some data to my server with the help of URLLoader, and I listen to the ProgressEvent, but it doesn\'t dispatch. No errors, files get uploaded successfully. Why could it not work?

I upload some data to my server with the help of URLLoader, and I listen to the ProgressEvent, but it doesn't dispatch. No errors, files get uploaded successfully. Why could it not work?

Code as follows:

//setup
urlLoader.addEventListener开发者_StackOverflow中文版(ProgressEvent.PROGRESS, onProgress);

//listen
private function onProgress(e:ProgressEvent):void {
    trace(e.bytesLoaded + ' ' + e.bytesTotal);
}


I'm late to this answer, but seeing as how I just ran into it myself, I thought I'd add my two cents:

The reason you are not seeing any progress events for a POST/upload is because the URLLoader doesn't dispatch progress events (or change the "bytesLoaded" property) for uploads. Sad, but true.


You don't show when you're actually calling the load() method. It should be :

 //setup
 urlLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);
 urlLoader.load( new URLRequest( url ) );


 //listen
 private function onProgress(e:ProgressEvent):void {
    trace(e.bytesLoaded + ' ' + e.bytesTotal);
 }


I presume the urlLoader is a loader object instance? If so you need to add the eventListener to the contentLoaderInfo property.

urlLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号