Jump to content


Photo

percent to pixels


  • Please log in to reply
7 replies to this topic

#1 The Little Guy

The Little Guy

    Advanced Member

  • Members
  • PipPipPip
  • 6,676 posts

Posted 11 October 2008 - 02:06 PM

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

phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
Twitter: http://twitter.com/phpsnips
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

#2 JasonLewis

JasonLewis

    Advanced Member

  • Members
  • PipPipPip
  • 3,351 posts
  • LocationVictoria, Australia

Posted 11 October 2008 - 07:43 PM

Wouldn't you do the same thing as the percentage but multiply it by the width of the timeline?
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 corbin

corbin

    Advanced Member

  • Staff Alumni
  • 8,129 posts

Posted 11 October 2008 - 11:30 PM

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.....
Why doesn't anyone ever say hi, hey, or whad up world?

#4 The Little Guy

The Little Guy

    Advanced Member

  • Members
  • PipPipPip
  • 6,676 posts

Posted 12 October 2008 - 12:00 AM

Im confused, do you happen to have an example?
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
Twitter: http://twitter.com/phpsnips
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

#5 corbin

corbin

    Advanced Member

  • Staff Alumni
  • 8,129 posts

Posted 12 October 2008 - 12:45 AM

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.
Why doesn't anyone ever say hi, hey, or whad up world?

#6 The Little Guy

The Little Guy

    Advanced Member

  • Members
  • PipPipPip
  • 6,676 posts

Posted 12 October 2008 - 01:10 AM

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.
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
Twitter: http://twitter.com/phpsnips
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

#7 JasonLewis

JasonLewis

    Advanced Member

  • Members
  • PipPipPip
  • 3,351 posts
  • LocationVictoria, Australia

Posted 12 October 2008 - 02:42 AM

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;

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#8 corbin

corbin

    Advanced Member

  • Staff Alumni
  • 8,129 posts

Posted 12 October 2008 - 12:52 PM

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)
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com