I’m working on a scrollbar and I’ve reached a roadblock. I’m stuck on making the scrollbar move when a “scroll up” or “scroll down” button is pressed. I’ve got it working so when you drag the scrollbar, the text scrolls, but I’m having a little difficulty reverse-programming the code used to do that. here’s my code:
this.stop(); //stops on current frame
var what_to_scroll:TextField = _parent.outputTxt;
//the text field that we will be scrolling
var barY:Number = scroll_bar._y;
//get y-axis coordinate for draggable scroll bar
var btnHeight:Number = (scroll_up._height / 2);
//get button height so scroll bar doesn't move through it
var initialTimeInterval:Number = 500;
var constantTimeInterval:Number = 100;
var scrollSpeedInterval:Number = 1;
//these 3 variables are the time before starting a scroll interval, the time between them when scrolling, and scroll speed
//----------------------------------------------------------------------------------------------------------------------------------------------
//all events go here
scroll_up.onPress = scrollUp; //scroll text box up
scroll_down.onPress = scrollDown; //scroll text box down
scroll_up.onRelease = scrollRelease; //stop scrolling when button is released
scroll_down.onRelease = scrollRelease; //stop scrolling when the button is released
scroll_bar.onPress = clickBar; //when the user clicks the scroll bar
scroll_bar.onRelease = releaseBar; //when the user releases the scroll bar
scroll_bar.onReleaseOutside = releaseBar; //when the user releases the scroll bar outside of the drag area
//----------------------------------------------------------------------------------------------------------------------------------------------
//all functions that get called by events go here
function scrollUp():Void {
//scroll the text box up
topScroll = 1; //top-most scrolling position
what_to_scroll.scroll != topScroll ? what_to_scroll.scroll-- : what_to_scroll.scroll = topScroll;
beginScroll = setTimeout(function() {
scrollText = setInterval(function() {
what_to_scroll.scroll != topScroll ? what_to_scroll.scroll-- : what_to_scroll.scroll = topScroll;
}, constantTimeInterval);
}, initialTimeInterval);
//scroll text box up
}
function scrollDown():Void {
//scroll the text box up
bottomScroll = what_to_scroll.maxscroll; //bottom-most scrolling position
what_to_scroll.scroll != bottomScroll ? what_to_scroll.scroll++ : what_to_scroll.scroll = bottomScroll;
beginScroll = setTimeout(function() {
scrollText = setInterval(function() {
what_to_scroll.scroll != bottomScroll ? what_to_scroll.scroll++ : what_to_scroll.scroll = bottomScroll;
}, constantTimeInterval);
}, initialTimeInterval);
//scroll text box down
}
function scrollRelease():Void {
//stop scrolling when the button is released
clearInterval(scrollText);
clearTimeout(beginScroll);
}
function clickBar():Void {
//when the user clicks the scroll bar
this.startDrag(false,
this._x,
scroll_up._y + btnHeight + (scroll_bar._height / 2) - 0.25,
this._x,
scroll_down._y - btnHeight - (scroll_bar._height / 2) + 0.50);
//begin dragging scroll bar
//we add/subtract 0.25/0.50 from the y-axis constraints on the scroll bar to make up for the stroke around the scroll bar
scroll_text = setInterval(scrollBar, scrollSpeedInterval); //scroll text
}
function releaseBar():Void {
//when the user releases the scroll bar
clearInterval(scroll_text); //stop scrolling
this.stopDrag(); //stop dragging scroll bar
}
function scrollBar():Void {
//scroll text box
position = (scroll_bar._y + barY) / (bar._height - scroll_bar._height); //get scroll bar coordinates
what_to_scroll.scroll = Math.round(position * what_to_scroll.maxscroll); //set text box position to coordinates
}
Any help on this? It ill be mostly appreciated! :te:
Cheers,
-Mike