I'm writing an application that involves a user posting significant
amounts of text. I'd like to be able to monitor the status of the upload
but from various posts around I've discovered that the ProgressEvent is
only dispatched during the download when you use URLLoader. Can anyone
suggest a way to make this happen? I've been thinking of extending the
socket class for this reason but I'd be working in unfamiliar ground if
that's the case.

Here's a sample mxml that demonstrates the simplified idea.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" initialize="fillText()"> <mx:Script>  <!--[CDATA[  
import flash.utils.setTimeout;   import flash.net.*;   private var
myLoader:URLLoader      public function fillText():void   {   }  
private function handleSubmit():void   {    var data:ByteArray = new
ByteArray();    while (data.length < 1000000)    {    
data.writeUTF("012345678901234567890123456789012345678901234567890123456\
789012345678901234567890123456789012345678901234567890123456789012345678\
901234567890123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890123456789012\
3456789\n");    }    progress.text += "About to upload " + data.length +
"B\n";    var req:URLRequest = new
URLRequest("http://192.168.6.204:8081/portal/upload.rvt";);    req.data =
data;    req.method = URLRequestMethod.POST    myLoader = new
URLLoader();    myLoader.addEventListener(ProgressEvent.PROGRESS,
handleProgress);    myLoader.addEventListener(Event.COMPLETE,
handleComplete);    myLoader.load(req);    setTimeout(checkLoader,500);
}   private function handleProgress(e:ProgressEvent):void   {   
progress.text += e.bytesLoaded + "/" + e.bytesTotal + " loaded\n";   }  
private function handleComplete(e:Event):void   {    progress.text +=
"Complete.\n";   }   private function checkLoader():void   {   
progress.text += myLoader.bytesLoaded + " sent\n";   
setTimeout(checkLoader,500);   }  ]]--> </mx:Script>  <mx:Panel
layout="vertical" title="Upload Progress" horizontalcenter="0"
verticalcenter="0">   <mx:Button id="submit" label="Submit"
click="handleSubmit()">   <mx:TextArea id="progress" width="400"
height="300">  </mx:TextArea> </mx:Button>  </mx:Panel></mx:Application>

Thanks in advance for any advice.  CM

Reply via email to