Jump to content

percent to pixels


Recommended Posts

this is more of ActionScript Math question, so here is my prob:

 

I am loading a video, and I have a:

- preloader

- timeLine

- scrubber

 

This converts the loaded bytes of the totoal size to a percentage:

var btsLoaded:Number = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal * 100);

 

what I need to do, is get the loaded amount, get the width of the timeLine, and figure how wide the preloader should be. So...

100% loaded needs to equal the width of the timeLine

50% loaded needs to equal the half the width of the timeLine

and so on...

 

this works the same as YouTube's video loader, and all the others.

 

timeLine width:

controlsBG.timeLine.vidLen._width // timeLine width

 

Link to comment
Share on other sites

Basic concept of a percentage is x/100.  x% means x/100 (in simple terms).  So, when you're taking Math.round(my_ns.bytesLoaded/my_ns.bytesTotal * 100); to make it a percent, you need to divide it by 100 again to get a usable number for multiplication.

 

 

 

Why do so many people have problems with percentages.....

Link to comment
Share on other sites

You're confused?!?!??!?!?!?!

 

 

No offense, but.... What?!?!?!?!

 

 

Enough with the rudeness and way over use of question/exclamation marks now:

 

 

w = round(l/t*b)

 

Where w = width representation (in px) of finished, l = loaded, t = total, b = total width of bar.

Link to comment
Share on other sites

That's exactly what I said corbin, isn't it? :P

 

Try this TLG:

ratio = Math.round((my_ns.bytesLoaded/my_ns.bytesTotal) * controlsBG.timeLine.vidLen._width);
controlsBG.timeLine.loadedAmt._width = ratio;

 

 

Never said that's not what you said ;p.  Just gave him a concrete example like he asked.

 

 

 

(Also, I was explaining that x percent is not what he should be multiplying by.  He should multiply by x%/100 or the original ratio ;p)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.