# percent to pixels

7 replies to this topic

### #1 The Little Guy

The Little Guy
• Members
• 6,676 posts

Posted 11 October 2008 - 07:06 PM

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

- 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
http://dreamhost.com (promo code: 8RN4)
\$30 off 1 year of hosting
\$40 off 2 years of hosting

### #2 JasonLewis

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

Posted 12 October 2008 - 12:43 AM

Wouldn't you do the same thing as the percentage but multiply it by the width of the timeline?
Jason / ProjectFear / Jaysonic

### #3 corbin

corbin
• Staff Alumni
• 8,129 posts

Posted 12 October 2008 - 04:30 AM

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
• Members
• 6,676 posts

Posted 12 October 2008 - 05: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
http://dreamhost.com (promo code: 8RN4)
\$30 off 1 year of hosting
\$40 off 2 years of hosting

### #5 corbin

corbin
• Staff Alumni
• 8,129 posts

Posted 12 October 2008 - 05: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
• Members
• 6,676 posts

Posted 12 October 2008 - 06:10 AM

If this is what you mean:
```ratio = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal*controlsBG.timeLine.vidLen._width);

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
http://dreamhost.com (promo code: 8RN4)
\$30 off 1 year of hosting
\$40 off 2 years of hosting

### #7 JasonLewis

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

Posted 12 October 2008 - 07:42 AM

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

Try this TLG:
```ratio = Math.round((my_ns.bytesLoaded/my_ns.bytesTotal) * controlsBG.timeLine.vidLen._width);
```

Jason / ProjectFear / Jaysonic

### #8 corbin

corbin
• Staff Alumni
• 8,129 posts

Posted 12 October 2008 - 05:52 PM

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

Try this TLG:

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

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