scroll bar maths?!

  • kfc06
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jul 28, 2009
  • Posts: 12
  • Status: Offline

Post August 17th, 2009, 7:14 am

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)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 17th, 2009, 7:14 am

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post August 18th, 2009, 3:58 am

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.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • kfc06
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jul 28, 2009
  • Posts: 12
  • Status: Offline

Post August 22nd, 2009, 1:38 am

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
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post August 25th, 2009, 3:10 am

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.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 59 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.