maguskrool
Technical User
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!
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;
}