Scrollbar won't scroll text.
I followed a nice scrollbar tutorial here on Flashkit, and everything works- the buttons and whatnot- except the scrollbar itself. I can click and drag it just fine, but the arrows won't move it up and down, and the text doesn't scroll with the bar.
My code is posted below; I'm hoping someone can point out what is wrong.
I starred out what I think are the important bits.
Code:
onClipEvent (load) {
//Text in scroll box.
whoText = "<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\">
<FONT FACE=\"Georgia\" SIZE=\"18\" COLOR=\"#EDDABB\">
Title Here</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING=\"2\">
<P ALIGN=\"LEFT\"><FONT FACE=\"Georgia\" SIZE=\"12\" COLOR=\"#EDDABB\">Lots of text here.
</FONT></P></TEXTFORMAT>";
scrolling = 0;
frameCounter = 1;
speedFactor = 2;
numLines = 20;
origHeight = scrollbar._height;
origX = scrollbar._x;
function initScrollbar() {
var totalLines = numLines+whoText.maxscroll-1;
scrollbar._yscale = 100*(numLines)/totalLines;
deltaHeight = origHeight-scrollbar._height;
lineHeight = deltaHeight/(whoText.maxScroll-1);
}
function updateScrollBarPos() {
scrollbar._y = lineHeight*(whoText.scroll-1);
}
}
onClipEvent (enterFrame) {
//if (whoText.maxscroll>1) {
initScrollbar();
//}
if (frameCounter%speedFactor == 0) {
if (scrolling == "up" && whoText.scroll>1) {
whoText.scroll--;
updateScrollBarPos();
} else if (scrolling == "down" && whoText.scroll<whoText.maxscroll) {
whoText.scroll++;
updateScrollBarPos();
}
frameCounter = 0;
}
frameCounter++;
}
onClipEvent (mouseDown) {
if (up.hitTest(_root._xmouse, _root._ymouse)) {
scrolling = "up";
frameCounter = speedFactor;
up.gotoAndStop(2);
}
if (down.hitTest(_root._xmouse, _root._ymouse)) {
scrolling = "down";
frameCounter = speedFactor;
down.gotoAndStop(2);
}
//**********
if (scrollbar.hitTest(_root._xmouse, _root._ymouse)) {
scrollbar.startDrag(0, origX, deltaHeight, origX);
scrolling = "scrollbar";
}
updateAfterEvent();
}
//**********
onClipEvent (mouseUp) {
scrolling = 0;
up.gotoAndStop(1);
down.gotoAndStop(1);
stopDrag();
updateAfterEvent();
}
//**********
onClipEvent (mouseMove) {
if (scrolling == "scrollbar") {
whoText.scroll = Math.round((scrollbar._y)/lineHeight+1);
}
updateAfterEvent();
}
//**********