Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preloading several files, showing one combined "% loaded" value

Status
Not open for further replies.

maguskrool

Technical User
Dec 11, 2006
77
0
0
PT
Hello everyone.

For this website I'm developing I need to preload several files (images, xml, css and the main .swf). I have a preloader and I want it to show the total % loaded of the sum of all those files. From what I've learned so far, I need a ProgressEvent instance and its _bytesTotal and _bytesLoaded properties. I've managed to calculate the sum of all the file sizes (see code, perhaps there are simpler ways), but I'm puzzled as how to obtain a sum of all the files' _bytesLoaded. I thought of using a similar counter to the one I created for the sum of the _bytesTotal (_nTotalBytes), but I'm not sure how to reset it when I need to provide a new sum and even if the way the files are loaded (is there a coherent order I can depend on?) allows me to use this sort of approach.

Any thoughts on this are appreciated, thanks!

Code:
//will hold the sum of all files' bytesTotal
private var _nTotalBytes:Number = 0;

//slightly different for xml or css
var myFile = new Loader();
myFile.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, _allBytesTotal);
myFile.load(new URLRequest("content.swf");

//event handler
private function _allBytesTotal (evt:ProgressEvent):void {
evt.target.removeEventListener(ProgressEvent.PROGRESS, _allBytesTotal);
_nTotalBytes += evt.target.bytesTotal;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top