CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Adobe Flex (http://www.codingforums.com/forumdisplay.php?f=63)
-   -   How to properly use ProgressEvent's bytesLoaded and bytesTotal for file download (http://www.codingforums.com/showthread.php?t=231315)

bon_t 07-06-2011 11:01 PM

How to properly use ProgressEvent's bytesLoaded and bytesTotal for file download
 
Hi All,

I am using Flex 4, Actionscript 3.

I am using FileReference's download method, which automatically opens the "Save As" dialog window (ie. I don't have to explicitly call browse like for an upload).

I'd like the label of my ProgressBar component to display
downloading <%> ...

In my ProgressEvent handler, I tried
Code:

        prgbr_fileDownload.label = "downloading %3%%...";
        prgbr_fileDownload.setProgress( event.bytesLoaded, event.bytesTotal );

But this just displayed "downloading ...". I already set the mode of my ProgressBar component to "manual".

I then tried
Code:

prgbr_fileDownload.label = "downloading " + Math.round( ( event.bytesLoaded/event.bytesTotal ) * 100 ) + "% ...";
And I was shocked to see very large numbers.

I then noticed my trace statements displaying the following:
progressHandler name = g2.zip bytesLoaded = 98304 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 196608 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 377421 bytesTotal = 98304
etc.
progressHandler name = g2.zip bytesLoaded = 17820389 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 17829381 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 17838373 bytesTotal = 98304
etc.
progressHandler name = g2.zip bytesLoaded = 29940557 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 30012485 bytesTotal = 98304
progressHandler name = g2.zip bytesLoaded = 30103874 bytesTotal = 98304

Hence, obviously my last computation would not work.

How can I get the percentage downloaded to be displayed correctly?

Thanks,
Bonnie


All times are GMT +1. The time now is 09:10 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.