scroll bar maths?!

  • kfc06
  • Newbie
  • Newbie
  • kfc06
  • Posts: 12

Post 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. :hmm:

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 ]
function updateScroller(type) {
   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);
   }
}
 
  1. function updateScroller(type) {
  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)
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 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.
  • kfc06
  • Newbie
  • Newbie
  • kfc06
  • Posts: 12

Post 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++;
            }
            updateScroller("arrow");
         };
      } else {
         this.onMouseMove = function() {
            updateScroller("mid");
            updateAfterEvent();
         };
      }
   } else {
      this.onEnterFrame = null;
      this.onMouseMove = null;
   }
};
function updateScroller(type) {
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.             }
  11.             updateScroller("arrow");
  12.          };
  13.       } else {
  14.          this.onMouseMove = function() {
  15.             updateScroller("mid");
  16.             updateAfterEvent();
  17.          };
  18.       }
  19.    } else {
  20.       this.onEnterFrame = null;
  21.       this.onMouseMove = null;
  22.    }
  23. };
  24. function updateScroller(type) {
  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. }
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 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 17 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.