Oops, spotted a mistake!

This line...
var currentImageProgress:Number = (
currentImage.getBytesLoaded()/currentImage.getBytesTotal()
)/100;
...should be...
var currentImageProgress:Number = (
currentImage.getBytesLoaded()/currentImage.getBytesTotal()
)*100;

(multiply by 100 at the end)

A.

On 3/12/06, Adrian Park <[EMAIL PROTECTED]> wrote:
>
> Hey Sascha,
>
> I see what you mean - the main problem is you have no way of knowing the
> sum total of all the bytes to load when the download process starts.
>
> I like the idea of dividing the bar into segments, one per image. I think
> I'd try something like this:
>
> Lets say there are 5 images to load - image_1, image_2 e.t.c
> 100/5 = 20
> So, we need to map 0-100% of the bytesLoaded for image_1 to the 0-20%
> segment on our loading bar, then we map 0-100% of the bytesLoaded for
> image_2 to the 20-40% segment on our loading bar and so on, and so on...
>
> The code would look something like so (completely untested!)...
>
> var imageCount:Number = i; // total number of mc's to load
> var currentImageNo:Number = c; // the curent image number
> var currentImage:MovieClip = this["image_"+currentImageNo]; // reference
> to the current MovieClip/Image
> var segmentSize:Number = 100/imageCount; // the size of each segment on
> the loader bar
>
> // map progress to a segmented progress bar
> var currentImageProgress:Number = ( 
> currentImage.getBytesLoaded()/currentImage.getBytesTotal()
> )/100;
> var alreadyLoaded:Number = currentImageNo * segmentSize;
> /*
> Work out current image's progress as proportion of one segment
> i.e. if segmentSize=20, currentImageProgress=50
> currentImageProgressMapped=20*(50/100)=10
> */
> var currentImageProgressMapped:Number = segmentSize *
> (currentImageProgress/100);
> var totalCurrentProgress:Number = alreadyLoaded +
> currentImageProgressMapped;
>
> // finally, something like
> myProgressBar._xscale = totalCurrentProgress;
>
> Of course, the code could be abbreviated a bit but I've broken the steps
> of the calculation out for clarity - I hope it makes sense! Let me know if
> this gets you closer to what you are looking for.
>
> Cheers, Adrian P
>
>
> On 3/12/06, Sascha Balkau <[EMAIL PROTECTED]> wrote:
> >
> > Hi Adrian,
> >
> > thanks for the idea but this approach will not work in my case because
> > the
> > images are loaded sequencially. If one image is finished loading, my
> > class
> > starts loading the next and so on, one after one. And the amount of
> > images
> > varies (the image filenames are fetched from a XML file).
> > I'm now defining a segmentWidth by dividing the full progressbar width
> > by
> > the amount of images that are going to be loaded. That gives me the 100%
> > for
> > one image on the whol bar. I just haven't figured out yet how to make it
> > work so that the bar doesn't start from 0 at every image. Any other
> > idea?
> >
> > Sascha
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Adrian Park" < [EMAIL PROTECTED]>
> > To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
> > Sent: Sunday, March 12, 2006 3:24 AM
> > Subject: Re: [Flashcoders] Loading several images with one progressbar?
> >
> >
> > Say you have 3 images loading, use something like this:
> >
> > var bytesLoaded:Number = 0;
> > var bytesTotal:Number = 0;
> >
> > bytesLoaded += image1.getBytesLoaded();
> > bytesTotal += image1.getBytesTotal();
> > bytesLoaded += image2.getBytesLoaded();
> > bytesTotal += image2.getBytesTotal();
> > bytesLoaded += image3.getBytesLoaded();
> > bytesTotal += image3.getBytesTotal ();
> >
> > var percentageLoaded:Number = (bytesLoaded/bytesTotal) * 100;
> >
> > There may be ways to optimise this code depending on your circumstances
> > (e.g.
> > just calculate bytesTotal once and reuse it) but this shows the basic
> > idea.
> >
> > Adrian P.
> >
> >
> > On 3/11/06, Sascha Balkau <[EMAIL PROTECTED]> wrote:
> > >
> > > Hi,
> > > this is probably an old hat but I can't get it right. I want to
> > display
> > > the
> > > load progress of several images with one progress bar. How do I
> > calculate
> > > the percentage of the bar?
> > >
> > > Thanks alot,
> > > Sascha
> > >
> > > _______________________________________________
> > > Flashcoders@chattyfig.figleaf.com
> > > To change your subscription options or search the archive:
> > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > >
> > > Brought to you by Fig Leaf Software
> > > Premier Authorized Adobe Consulting and Training
> > > http://www.figleaf.com
> > > http://training.figleaf.com
> > >
> > _______________________________________________
> > Flashcoders@chattyfig.figleaf.com
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training
> > http://www.figleaf.com
> > http://training.figleaf.com
> >
> > _______________________________________________
> > Flashcoders@chattyfig.figleaf.com
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training
> > http://www.figleaf.com
> > http://training.figleaf.com
> >
>
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to