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
https://forums.phpfreaks.com/topic/128021-percent-to-pixels/
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
https://forums.phpfreaks.com/topic/128021-percent-to-pixels/#findComment-663178
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
https://forums.phpfreaks.com/topic/128021-percent-to-pixels/#findComment-663205
Share on other sites

If this is what you mean:

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

 

It doesn't work, it says that if it is 100% loaded, then it is only is 50% of the bar wide.

Link to comment
https://forums.phpfreaks.com/topic/128021-percent-to-pixels/#findComment-663208
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
https://forums.phpfreaks.com/topic/128021-percent-to-pixels/#findComment-663402
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.