I created this back in the days of SmartClips, Flash's precursor to Components (which actually made this obsolete a few months after creating it). I was successful in mimicking the Windows scrollbar exactly to use it in various Flash applications.

Try adding and deleting text to see the scrollbar adjust itself. Also try using the scrollbar as you normally would; drag it, click the arrows, click the negative space between the arrows and the dragable part, etc. Notice the delays when you click and hold the arrows ant the negative space.

The code that runs the clip is below. Feel free to download the FLA for a closer look.

Check out the rest of my portfolio if you came directly here.

Please upgrade your Flash Player and/or turn on Javascript
//The following variables are set by the smart clip
//pathToText="_root";
//textVariableName="text";
//textToLoad="text.txt";
//viewableLines = 15;


scrollBar._alpha=0;
setScroll=0;
scrollPause=false;
initializeScroll();


function initializeScroll(){
	grabHeight=this._height*((1/this._yscale)*100);
	scrollTop._yscale=(this._xscale/this._yscale)*100;
	scrollBottom._yscale=(this._xscale/this._yscale)*100;
	scrollBottom._y=grabHeight-scrollBottom._height;

	setScrollBar();
	setScrollBack();
}


function setScrollBar(){
	scrollBar._y=0;

	if(this[pathToText][textVariableName].maxscroll>1){
		scrollBackBottom.gotoAndStop("on");
		scrollTop.gotoAndStop("on");
		scrollBottom.gotoAndStop("on");
		scrollBar._height=(viewableLines/(this[pathToText][textVariableName].maxscroll+viewableLines-1))*(grabHeight-(scrollTop._height*2));

		if(scrollBar._height<(8*(this._xscale/this._yscale))){
			scrollBar._height=(8*(this._xscale/this._yscale));
		}

	}else{
		scrollBar._height=0;
		scrollBackBottom.gotoAndStop("off");
		scrollTop.gotoAndStop("off");
		scrollBottom.gotoAndStop("off");
	}

	scrollBar.scrollBarButtonBottom._yscale = ((100/scrollBar._yscale)*(this._xscale/100)*(100/this._yscale)) *100;
	scrollBar.scrollBarButtonTop._yscale = ((100/scrollBar._yscale)*(this._xscale/100)*(100/this._yscale)) *100;

	min = scrollTop._height;
	max = scrollBottom._y-scrollBar._height;

	scrollBar._y=min;
	scrollBar._alpha=100;
}


function dragScrollBar(){
	scrollBar._y=_ymouse+offsetY;

	if(scrollBar._y>max){
		scrollBar._y=max;
	}
	if(scrollBar._y<min){
		scrollBar._y=min;
	}

	moveText();
	setScrollBack();
}


function moveScrollBar(call_setScrollBack){
	this[pathToText][textVariableName].scroll+=setScroll;
	scrollBar._y=((((this[pathToText][textVariableName].scroll-1)*(max-min))/(this[pathToText][textVariableName].maxscroll-1))+min);
	scrollBarPosition=this[pathToText][textVariableName].scroll;

	setScrollBack();
}


function moveText(){
	scrollBarPosition=Math.ceil(((scrollBar._y-min)/(max-min))*(this[pathToText][textVariableName].maxscroll-1))+1;
	this[pathToText][textVariableName].scroll=scrollBarPosition;
}


function setScrollBack(){
	scrollBackTop._y = min;
	scrollBackTop._height = scrollBar._y - min;
	scrollBackBottom._y = scrollBar._y + scrollBar._height;
	scrollBackBottom._height = 0
	scrollBackBottom._height = max - scrollBackBottom._y + scrollBar._height;
}


currentMaxScroll = this[pathToText][textVariableName].maxscroll;
function adjustForTextChange(){
	if(currentMaxScroll != this[pathToText][textVariableName].maxscroll){
		setScrollBar();
		moveScrollBar();
		currentMaxScroll = this[pathToText][textVariableName].maxscroll;
	}
	if(scrollBarPosition != this[pathToText][textVariableName].scroll){
		moveScrollBar();
		setScrollBack();
	}
}

stop();


***********

onClipEvent(load){
	delayTime = 8;
	delayCount = 1;
}

onClipEvent (enterFrame) {
	if (_parent.setScroll != 0) {
		if(_parent.scrollPause==false){
			if(delayCount<delayTime){
				if(delayCount==1){
					//move it once
					_parent.moveScrollBar();
				}
				delayCount++;
			}else{
				_parent.moveScrollBar();
			}
		}
	}else{
		delayCount = 1;
	}
	_parent.adjustForTextChange();
}