-
total percentage calculation
Hi,
I'm making a preloader which calculates the percentage of the image being loaded through the xml. I'm loading them one by one which works fine.
My preloader works fine too. This is the code till now:
Code:
function PL_LOADING(event:ProgressEvent):void{
var pcent:int=event.bytesLoaded/event.bytesTotal*100;
var countImg:int = i+1;
var total:Number = (i+1)/xmlLength*100;
(root as MovieClip).percImage.text = pcent + "%";
(root as MovieClip).countImage.text = "loAding imAge " + countImg + " of " + xmlLength;
(root as MovieClip).totalPerc.text = "TotAl : "+ total.toFixed(2) + "%";
}
I've got my percentage for the single file. And also how many images will be loaded. For now, my total percentage is the 'var total:Number = (i+1)/xmlLength*100;', which works. But it's "choppy". It goes from 0% directly to for example 23.33 to 44.44 to 65.55 to...
I want this to be fluid. So that it goes fluently from 0.0 to the first percentage of the total amount, when the next images loads, fluent from the first percentage to the second... and so on and on.
But I'm not good at math. How can I calculate that overall percentage to get that fluent counting? I have the "fluid" percentage of the single file, the number of the current file being loaded and the total amount of files to be loaded. So I should be able to calculate it with a formula, right?
Anyone good at math?
Cheers
-
with the help a post at http://board.flashkit.com/board/show...hlight=percent I think I managed to make the formula.
I ended up with:
Code:
var pcent:int=event.bytesLoaded/event.bytesTotal*100;
var countImg:int = i+1;
var total:Number = (i+1)/xmlLength*100;
var total2:Number = 1/xmlLength*100;
var totalImg:Number = (i*total2)+(total2*(pcent/100));
the var totalImg should be the formula. It seems to work, but I thought I should post it here to let you know that I probably have the solution and some mathwiz could verify it.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|