A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: total percentage calculation

  1. #1
    Senior Member
    Join Date
    Dec 2002
    Posts
    175

    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
    http://www.EyeEmotion.be/: just here to give you a nice treatment for the eye


  2. #2
    Senior Member
    Join Date
    Dec 2002
    Posts
    175
    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
    http://www.EyeEmotion.be/: just here to give you a nice treatment for the eye


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center