Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2011, 11:01 PM   PM User | #1
bon_t
New Coder

 
Join Date: Jul 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
bon_t is an unknown quantity at this point
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
bon_t is offline   Reply With Quote
Reply

Bookmarks

Tags
bytesloaded, bytestotal, filereference.download, flex4, progressevent

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:49 AM.


Advertisement
Log in to turn off these ads.