# scroll bar maths?!

• Newbie
• Posts: 12

3+ Months Ago

I have the code below that i am looking to try to amend to use my custom scroller, any one able to help me figure out what code i need to know to make it work for me properly? using it in its current state it does move the bar up and down, and display all the relevant info, its just the bar doesnt visually appear at the bottom or top of the window (only the middle). I figure it will be something to do with the variables not matching my dimensions, but i cant suss it.

Can anyone tell me what i need to know and what variables i need to change to get this thing to work?
ACTIONSCRIPT Code: [ Select ]
var a = target.scroll;
var b = target.maxscroll;
var c = 110;
var d = scroller._y;
if (type == "mid") {
target.scroll = Math.round((b*(d/c))+1);
} else {
scroller._y = c*((a-1)/b);
}
}

2.    var a = target.scroll;
3.    var b = target.maxscroll;
4.    var c = 110;
5.    var d = scroller._y;
6.    if (type == "mid") {
7.       target.scroll = Math.round((b*(d/c))+1);
8.    } else {
9.       scroller._y = c*((a-1)/b);
10.    }
11. }
12.

Any help appreciated.

(Actionscript 2)
• Guru
• Posts: 1252
• Loc: Ro

3+ Months Ago

i think you need something like this:
Code: [ Select ]
nPercent = (target._y - target.minscroll)*100 / (target.maxscroll - target.minscroll); // if minscroll is 0, you can simplify this
scrollKnob._y = (scrollBar._y + nPercent*(scrollBar._height - scrollKnob._height) / 100);
1. nPercent = (target._y - target.minscroll)*100 / (target.maxscroll - target.minscroll); // if minscroll is 0, you can simplify this
2. scrollKnob._y = (scrollBar._y + nPercent*(scrollBar._height - scrollKnob._height) / 100);

Where scrollBar is your scroll bar, and scrollKnob is the part that you actually drag along the bar.
• Newbie
• Posts: 12

3+ Months Ago

Thanks for the reply, i tried that but it doesnt work at all now, dont know if i applied it in the wrong place or if other code above it is now messing it up. I have named the MC instance scrollKnob and scrollBar and using the following code as an action frame. Also should i be zeroing any of the pivot points can this be causing any problems?:

ACTIONSCRIPT Code: [ Select ]
this.startScroll = function(active, type) {
if (active) {
this.type = type;
if (type != "mid") {
this.onEnterFrame = function() {
if (type == "up") {
this.target.scroll--;
} else if (type == "down") {
this.target.scroll++;
}
};
} else {
this.onMouseMove = function() {
updateAfterEvent();
};
}
} else {
this.onEnterFrame = null;
this.onMouseMove = null;
}
};
nPercent = (target._y - target.minscroll)*100 / (target.maxscroll - target.minscroll);
// if minscroll is 0, you can simplify this
scroller._y =  (scrollBar._y + nPercent*(scrollBar._height - scrollKnob._height) / 100);
}
1. this.startScroll = function(active, type) {
2.    if (active) {
3.       this.type = type;
4.       if (type != "mid") {
5.          this.onEnterFrame = function() {
6.             if (type == "up") {
7.                this.target.scroll--;
8.             } else if (type == "down") {
9.                this.target.scroll++;
10.             }
12.          };
13.       } else {
14.          this.onMouseMove = function() {
16.             updateAfterEvent();
17.          };
18.       }
19.    } else {
20.       this.onEnterFrame = null;
21.       this.onMouseMove = null;
22.    }
23. };
25. nPercent = (target._y - target.minscroll)*100 / (target.maxscroll - target.minscroll);
26. // if minscroll is 0, you can simplify this
27. scroller._y =  (scrollBar._y + nPercent*(scrollBar._height - scrollKnob._height) / 100);
28. }
• Guru
• Posts: 1252
• Loc: Ro

3+ Months Ago

I have a custom scrollbar for AS2, get the class + example here:
http://www.awake.ro/test/customscrollbar.zip
Copy this link and paste it into your browser (redirect is not allowed). It's an older version, but good enough to get an idea on the scrolling.

## Post Information

• Total Posts in this topic: 4 posts
• Users browsing this forum: No registered users and 4 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum