I might do something like: (warning, not tested, but in theory it should work)

var mcl:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.counts = {}; // keep track of each individual movieclip's progress
listener.onLoadProgress = function(mc, loaded, total)
{
     this.counts[mc] = loaded / total; // store the percent of each
movieclip's progress
     var n = 0;
     var sum = 0;
     for(var i in this.counts) // loop through all the progresses, and
count them & sum them
     {
             n++;
             sum+=this.counts[i];
     }
     var pcnt = sum / n; // find the average % complete
     trace("Overall percentage: "+Math.round(pcnt * 100)+"%");
}
mcl.addListener(listener);
mcl.loadClip(url1, target1);
mcl.loadClip(url2, target2);
mcl.loadClip(url3, target3);


-David R

On 11/21/05, Matt Ganz <[EMAIL PROTECTED]> wrote:
> hi dave. thanks for your response. i understand the problem. but i am
> now resetting currentWeight to 0 directly after i test what percentage
> i'm at and i'm still getting skewed values:
>
> here is my code:
>
> mclListener.onLoadProgress = function( targetMC, loadedBytes, totalBytes )
> {
>
>       currentWeight += loadedBytes;
>       var currentPercentage = Math.floor( ( currentWeight /
> totalWeight ) * 100 );
>
>         if( currentPercentage % 10 == 0 )
>         {
>                 trace( "another 10% completed" );
>         }
>
>         switch( String( currentPercentage ) )
>         {
>                 case "10" :
>                         trace( "10% has loaded..." );
>                         break;
>                 case "20" :
>                         trace( "20% has loaded..." );
>                         break;
>                 // etc...etc....);
>         }
>         currentWeight = 0;
> };
>
> when i test each external swf individually, i still get skewed
> results, for example:
>
> swf1 = 312KB = 316,020 bytes // the trace value is 353,483
> // NOW ADD
> swf2 987K = 1330176 byets // the trace value is 1079498
> // THEN ADD THIS
> swf3 2.6MB = 4056473 bytes// the trace value is 2819958
>
> i just can't seem to get this right. is there a better way i can approach 
> this?
>
> thanks again for your help. -- matt.
> On 11/18/05, David Rorex <[EMAIL PROTECTED]> wrote:
> > On 11/18/05, Matt Ganz <[EMAIL PROTECTED]> wrote:
> > > hi.
> > >
> > > i'm using the MovieClipLoader class to load a few swfs that are
> > > defined in an array a la:
> > >
> > >
> > > var totalWeight = 41079759; // total weight in bytes (3.9MB)
> > > var currentWeight = 0;
> > >
> > > var mainArray:Array = new Array( { path: "movie1.swf", id:
> > > "movie1_mc", depth: 1 },
> > >                                                                         { 
> > > path: "movie2.swf", id: "movie2_mc", depth: 2 },
> > >                                                                         { 
> > > path: "movie3.swf", id: "movie3_mc", depth: 3 });
> > >
> > > for( i:Number=0; i<mainArray.length; i++ )
> > > {
> > >                 _root.loadClip( mainArray[i].path, 
> > > this.createEmptyMovieClip(
> > > mainArray[i].id,        mainSwfArray[i].depth ) );
> > > }
> > >
> > > what i want to do is read how much is loaded of the total weight ( the
> > > sum of all swfs ) and target my preloader for every 10%. i assume the
> > > best place to read the loaded bytes is in the onLoadProgress handler
> > > for MCL, a la:
> > >
> > > mainMclListener.onLoadProgress = function( targetMC, loadedBytes, 
> > > totalBytes )
> > > {
> > >         currentWeight += loadedBytes;
> > >         var currentPercentage = Math.floor( ( loadedBytes / totalWeight ) 
> > > * 100 );
> > > }
> > >
> > > the 3 swfs weight approximately 3.9 megabytes but when i trace out the
> > > value of "currentWeight", i get this value:
> > >
> > > 407,970,619.....but this equals 389 megabytes, not 3.9. what am i
> > > doing wrong here?
> > >
> > > thanks for any tips. -- matt.
> >
> > It's because you are continuously adding to 'currentWeight', and never
> > resetting it to 0.
> >
> > For example, in the case of loading just one file:
> >
> > if my file was 1000 bytes, and the load progress was:
> > 200 bytes finished...
> > 300 bytes finished..
> > 500 bytes finished...
> > 700 bytes finished...
> > 1000 bytes finished...all done!
> >
> > then obviously, just adding those numbers together would be incorrect,
> > it would give me 2700, which means nothing.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to