this is just an undocumented class that shows how you can get the filesize of a file in a loaderqueue without completely loading the file (I kill the further loading once sizxe is obtained).
I only use this class once to get the totalbytes.
After that I usuyally hard-code this result in the rest off my app.

Here I get the total combined filesizes from a loaderQueue object which holds
the url for every "image" or clip to load.
This is just to give you an idea. the way I present the code is nt copy-paste-able.
______________________________________________________

// first builds the loaderQueue object !!!! // loaderQueue[index_ID].url


private function checkFileSizes(){
       //processLoaderQueue()
       var startTime=getTimer()
       var _CLASS=classHook;
       var FS:Array=new Array()
       var index_ID=0;
       for (index_ID; index_ID < loaderQueue.length; index_ID++){
FS[index_ID]=new getFileSize() //!!!!!!!!!!!!!!!!!!!!! check down
       FS[index_ID].ID=index_ID
       FS[index_ID].onSize=function(){
               if(this.size==-1){
               trace("error getting filesize")
               }else{
               _CLASS.allFilesBytesTotal+=this.size
               }
               _CLASS.loaderQueue[this.ID].size=this.size
               _CLASS.totalChekedFileSizes++
               if(_CLASS.totalChekedFileSizes==_CLASS.loaderQueue.length){
var loadTime=(getTimer()-startTime)/1000 dbg.dbg('totalChekedFileSizes: ' + _CLASS.totalChekedFileSizes+' in '+loadTime+' seconds') dbg.dbg("FILESIZE "+(_CLASS.allFilesBytesTotal/1048576)+" MB / "+_CLASS.allFilesBytesTotal)
               _CLASS.processLoaderQueue()
}
       }
       FS[index_ID].url=loaderQueue[index_ID].url
} }

_______________________________________________________-



class nl.latcho.util.file.getFileSize extends MovieClip{ private var classRoot:getFileSize;
   private var mediaURL:String=null;
   private var mediaSize:Number=null;
   private var temp_mc:MovieClip;
   private var mc_loader:MovieClipLoader
   private var loadListener:Object;
public var onSize:Function;

public function getFileSize(){ classRoot=this; } public function set url(URL_str:String){
       if(temp_mc==null){
//creates temporary mc container for MovieClipLoader with unique random name; var temp_mc_str:String="fileSizeCheckTmp"+random(100000)+"-"+random(100000)+"-"+random(100000)+"_mc" temp_mc=_root.createEmptyMovieClip(temp_mc_str,_root.getNextHighestDepth())
           temp_mc._visible=false
           temp_mc._x=temp_mc._y=-3333
       }
       mediaURL=URL_str;
       checkSize()
   }//endd set url
public function get size():Number{
       return mediaSize;
   }
private function checkSize(){
   if(mediaURL){
       var CR:getFileSize=classRoot;
       mc_loader=new MovieClipLoader()
       loadListener=new Object()
       mc_loader.addListener(loadListener);
loadListener.onLoadProgress=function(targ_mc:MovieClip,curBytes:Number,ttlBytes:Number){
               CR.stopLoading(targ_mc)
               CR.mediaSize=ttlBytes;
               CR.mediaSize=ttlBytes;
//trace("CHECKEDFILES:"+targ_mc+"size:"+ttlBytes+" url:"+CR.mediaURL) CR.onSize(); // call - for the user to define: remoteFileSize.onSize=function(){myMediaSize=this.size} delete this;
           }
loadListener.onLoadError=function(targ_mc:MovieClip){ CR.stopLoading(targ_mc) //trace("CHECKEDFILES:"+targ_mc+"size:"+ttlBytes+" url:"+CR.mediaURL) CR.mediaSize=-1 CR.onSize(); // call - for the user to define: remoteFileSize.onSize=function(){myMediaSize=this.size} trace("remoteFileSize loadError:size=-1 :"+ CR.mediaURL)
               delete this;
} loadListener.onLoadComplete=function(targ_mc:MovieClip){ trace("COMPLETED [remoteFileSize/checkSize]:"+targ_mc+ " this should hardly happen, only if file is small or cached or local") } mc_loader.loadClip(mediaURL,temp_mc) }else{
           trace("remoteFileSize: no url specified")
       }
   }

private function stopLoading(targ_mc){ mc_loader.removeListener(loadListener) mc_loader.unloadClip(targ_mc)
       temp_mc.removeMovieClip()
   }
}//end remoteFileSize

Sascha Balkau 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" <[email protected]>
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

_______________________________________________
[email protected]
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

_______________________________________________
[email protected]
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
_______________________________________________
[email protected]
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


_______________________________________________
[email protected]
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