A Flash Developer Resource Site

# Thread: [f8] Making a scrollbar resize relative to the length of the content

1. ## [f8] Making a scrollbar resize relative to the length of the content

Okay, it seems I'm way too far out of highschool to remember how to do this anymore.

Basically I have a scrollbar but I want the actual scroller to change size relative to the content loaded, obviously not exceeding the size of the scroll track or becoming smaller.

these are my base variables.

Code:
```	var scrollHeight:Number  =  scrollTrack._height;
var contentHeight:Number = desc_mc._height+20;
var scrollFaceHeight:Number = scrollFace._height;
I would be most appreciative of any help, my brain just can't seem to remember these equations at all anymore...

2. If you set it up with proportions, it becomes simple.
Here's how I would do it:

first, get the amount that can be seen on the screen at one time (maskHeight)
now, find it's size with proportion to the entire content area (contentHeight):

Code:
`var viewRatio:Number = maskHeight/contentHeight`
So now, we want to pretend that the scrolling track represents the entire content area, and the scroller button represents the viewable area, so we can say:

Code:
`scrollerButtonHeight = scrollHeight*viewRatio`
and that's the height you need.

The concept is this: if the mask height is half of the content height, our viewRatio would be 50% (0.5)... so that also means we make the height of the button 50% of the scrolling track.

Another nice thing that comes out of this is that if the viewRatio is >= 1 then we know that the content's size is less than the mask... so you can just hide the scroller.

3. I forgot to say thanks, that helped alot.

It's always the math stuff that stumps me in flash, so annoying really... Maybe I should invest in some math texts...

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap