SimpleScrollBar class AS3

Here’s an AS3 class that creates a simple scroll bar. Set this as the Base Class for any movie clip. The container clip must have two movie clips named drag_mc and track_mc. These clips act as the dragger and track for the scroll bar

Add an event listener to call a handler when the scroll bar is dragged. SimpleScrollBar dispatches the ScrollBarEvent.UPDATE which includes the property scroll_value. This property holds a value from 0 to 1 representing the position of the dragger.

Here’s some example code. Assume that scroll_mc is a movie clip that contains two clips drag_mc and track_mc. This clip has SimpleScrollBar set as it’s base class.

scroll_mc.addEventListener( ScrollBarEvent.UPDATE, on_update );
function on_update( e:ScrollBarEvent ):void {
	var n:Number = e.scroll_value; // Get the value of scroll bar
	scroll_txt.scrollV = Math.round( ( scroll_txt.maxScrollV - 1 ) * n ) + 1;
}

Download the sample: simplescrollbar-class

One thought on “SimpleScrollBar class AS3”

Comments are closed.