# Horizontal scroll bar

**URL:** <https://forum.kirupa.com/t/horizontal-scroll-bar/327273>\
**Category:** Uncategorized\
**Created:** [February 17, 2012, 3:22pm UTC](https://forum.kirupa.com/t/horizontal-scroll-bar/327273 "2012-02-17T15:22:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![curvwind8](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@curvwind8](https://forum.kirupa.com/u/curvwind8)\
**Post date:** [February 17, 2012, 3:22pm UTC](https://forum.kirupa.com/t/horizontal-scroll-bar/327273/1 "2012-02-17T15:22:52Z")

</div>

hello all.

i have a horizontal scrollbar that scrolls content from left to right. it’s all working perfectly except for the dragger. when you click the dragger and move left to right it doesn’t stay within it’s “track.” when i use the left and right arrows there’s no problem. does anyone have any insight by looking at the code below?

much appreciated!

```auto
fscommand("allowscale", "false");
bar.useHandCursor = dragger.useHandCursor=false;
space = 20;
friction = 0.9;
speed = 4;
x = dragger._x;
top = main._x;
bottom = main._x+mask_mc._width-main._width-space;

dragger.onPress = function() {
	drag = true;
	this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y+this._parent.bar._width-this._width);
	dragger.scrollEase();
};
dragger.onMouseUp = function() {
	this.stopDrag();
	drag = false;
};
bar.onPress = function() {
	drag = true;
	if (this._parent._xmouse>this._x+this._width-this._parent.dragger._width) {
		this._parent.dragger._x = this._parent._xmouse;
		this._parent.dragger._x = this._x+this._width-this._parent.dragger._width;
	} else {
		this._parent.dragger._x = this._parent._xmouse;
	}
	dragger.scrollEase();
};
bar.onMouseUp = function() {
	drag = false;
};
moveDragger = function (d) {
	if ((dragger._x>=x+bar._width-dragger._width && d == 1) || (dragger._x<=x && d == -1)) {
		clearInterval(myInterval);
	} else {
		dragger._x += d;
		dragger.scrollEase();
		updateAfterEvent();
	}
};
up_btn.onPress = function() {
	myInterval = setInterval(moveDragger, 18, -1);
};
down_btn.onPress = function() {
	myInterval = setInterval(moveDragger, 18, 1);
};
up_btn.onMouseUp = down_btn.onMouseUp=function () {
	clearInterval(myInterval);
};
MovieClip.prototype.scrollEase = function() {
	this.onEnterFrame = function() {
		if (Math.abs(dx) == 0 && drag == false) {
			delete this.onEnterFrame;
		}
		r = (this._x-x)/(bar._width-this._width);
		dx = Math.round((((top-(top-bottom)*r)-main._x)/speed)*friction);
		main._x += dx;
	};
};

```
