# Scrolling horizontally

**URL:** <https://forum.kirupa.com/t/scrolling-horizontally/275507>\
**Category:** Uncategorized\
**Created:** [November 14, 2008, 6:00pm UTC](https://forum.kirupa.com/t/scrolling-horizontally/275507 "2008-11-14T18:00:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickedxawesome](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wickedxawesome](https://forum.kirupa.com/u/wickedxawesome)\
**Post date:** [November 14, 2008, 6:00pm UTC](https://forum.kirupa.com/t/scrolling-horizontally/275507/1 "2008-11-14T18:00:30Z")

</div>

I just made a scroll area with buttons and draggable items. All the code is written for vertical scrolling, the content I need to be scrolled is going to be horizontal. how can I rewrite this code to be horizontal scrolling? it seems like the scroll button (the one you drag along) doesn’t stay confined to its scroll line either.

scrolling = function () {  
var scrollHeight:Number = scrollTrack.\_height;  
var contentHeight:Number = contentMain.\_height;  
var scrollFaceHeight:Number = scrollFace.\_height;  
var maskHeight:Number = maskedView.\_height;  
var initPosition:Number = scrollFace.\_y=scrollTrack.\_y;  
var initContentPos:Number = contentMain.\_y;  
var finalContentPos:Number = maskHeight-contentHeight+initContentPos;  
var left:Number = scrollTrack.\_x;  
var top:Number = scrollTrack.\_y;  
var right:Number = scrollTrack.\_x;  
var bottom:Number = scrollTrack.\_height-scrollFaceHeight+scrollTrack.\_y;  
var dy:Number = 0;  
var speed:Number = 10;  
var moveVal:Number = (contentHeight-maskHeight)/(scrollHeight-scrollFaceHeight);

scrollFace.onPress = function() {  
var currPos:Number = this.\_y;  
startDrag(this, false, left, top, right, bottom);  
this.onMouseMove = function() {  
dy = Math.abs(initPosition-this.\_y);  
contentMain.\_y = Math.round(dy\*-1\*moveVal+initContentPos);  
};  
};  
scrollFace.onMouseUp = function() {  
stopDrag();  
delete this.onMouseMove;  
};  
btnUp.onPress = function() {  
this.onEnterFrame = function() {  
if (contentMain.\_y+speed\<maskedView.\_y) {  
if (scrollFace.\_y\<=top) {  
scrollFace.\_y = top;  
} else {  
scrollFace.\_y -= speed/moveVal;  
}  
contentMain.\_y += speed;  
} else {  
scrollFace.\_y = top;  
contentMain.\_y = maskedView.\_y;  
delete this.onEnterFrame;  
}  
};  
};  
btnUp.onDragOut = function() {  
delete this.onEnterFrame;  
};  
btnUp.onRollOut = function() {  
delete this.onEnterFrame;  
};  
btnDown.onPress = function() {  
this.onEnterFrame = function() {  
if (contentMain.\_y-speed\>finalContentPos) {  
if (scrollFace.\_y\>=bottom) {  
scrollFace.\_y = bottom;  
} else {  
scrollFace.\_y += speed/moveVal;  
}  
contentMain.\_y -= speed;  
} else {  
scrollFace.\_y = bottom;  
contentMain.\_y = finalContentPos;  
delete this.onEnterFrame;  
}  
};  
};  
btnDown.onRelease = function() {  
delete this.onEnterFrame;  
};  
btnDown.onDragOut = function() {  
delete this.onEnterFrame;  
};

if (contentHeight\<maskHeight) {  
scrollFace.\_visible = false;  
btnUp.enabled = false;  
btnDown.enabled = false;  
} else {  
scrollFace.\_visible = true;  
btnUp.enabled = true;  
btnDown.enabled = true;  
}  
};  
scrolling();

I did the tutorial found here… [http://www.kirupa.com/developer/flash8/scrollbar.htm](http://www.kirupa.com/developer/flash8/scrollbar.htm)
