Dynamic text with scrollbar

You’re right that the code works…but it does more than I want it to and so does not specifically fulfill my requirements. I am trying to understand what the code does so that I can strip out the bits that I don’t need - but obviously I’m having trouble getting to grips with it which is why I emailed this forum - to get some help understanding it. :slight_smile: I will persevere - cheer anyway…

Just one question: why??

In all other GUI’s, like in this browser window for example, the scrollbars DO resize according to the content’s length, and that’s a very good feature as it gives a visual indication on how much scroll there is,
furthermore, the MX components were designed to be drag’n’drop usable, as simple as it can get, so if you just need a scrollbar, why not use it??

Because…I don’t necessarily want to use a standard bar for the actual scrollbar. If I use an image other than a bar - say an arrow - I don’t want it to scale and distort in relation to the amount of content. I want it’s proportions to remain the same hence the need to strip out the resizing part of the code.

Call me dumb… I think I deserve it… :frowning:

The thing is that I cannot picture what you want with this scrollbar if you do not want this to be resized… And I am not drunken… :frowning:

Hmm, not so sure about that…I think i smell whiskey :beam: ;).
Ok fella I will knock up a quick jpg to show what it might look like and why I don’t want the scrollbar to resize…and by the way I do appreciate your perseverance in understanding the issue. :slight_smile:

Back in a bit…

OK this should illustrate it better. On the left the scrollbar doesn’t resize but would work, in that when you drag it up and down the text moves accordingly. On the right the scrollbar does resize and as you can see also distorts. This is why I want the scrollbar to work (to scroll) but don’t want it to resize. :slight_smile:

Well… I think this will get you started… This isn’t working properly at the moment, but you can easily tweak it so that it could fit your need…

Basically what it needs is to calculate the number of lines that needs scrolling first, and calculate the distance between 0% and 100% for the scrollbar and divide it and apply it to the move…

I haven’t touched anything for the drag part, but as soon as you figure out how to do the previous one, you won’t be having much problem… :wink:

onClipEvent (load){
	this.loadVariables("text.txt");
	scrolling = 0;
	frameCounter = 1;
	speedFactor = 3;
	numLines = 7;
	resetOnNewFile = true;

	origHeight = scrollbar._height;
	origX = scrollbar._x;

	refreshRate = 12;
	refreshCounter = 0;
	refreshlastMaxscroll = 0;
	loaded = false;

	daTextBox.scroll = resetOnNewFile ? 1 : Math.min(daTextBox.maxscroll, daTextBox.scroll);
	var totalLines = numLines + daTextBox.maxscroll - 1;
	moveStep = Math.round((down._y - up._y) / totalLines);
}

onClipEvent (enterFrame){
	if( loaded ){

		if(refreshCounter % refreshRate == 0 && daTextBox.maxscroll != refreshLastMaxScroll){
			refreshLastMaxScroll = daTextBox.maxscroll;
			refreshCounter = 0;

		}
		refreshCounter++;
	}

	if( frameCounter % speedFactor == 0){

		if( scrolling == "up" && daTextBox.scroll > 1){
			daTextBox.scroll--;
			if (scrollbar._y > 0 + moveStep)
				scrollbar._y -= moveStep;
			else
				scrollbar._y = 0;
		}
		else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){
			daTextBox.scroll++;
			if (scrollbar._y < 85 - moveStep)
				scrollbar._y += moveStep;
			else
				scrollbar._y = 85;
		}
		frameCounter = 0;
	}
	frameCounter++;
}

onClipEvent (mouseDown){
	if(up.hitTest(_root._xmouse,_root._ymouse)){
		scrolling = "up";
		frameCounter = speedFactor;
		up.gotoAndStop(2);
	}
	if(down.hitTest(_root._xmouse,_root._ymouse)){
		scrolling = "down";
		frameCounter = speedFactor;
		down.gotoAndStop(2);
	}
	if(scrollbar.hitTest(_root._xmouse,_root._ymouse)){
		scrollbar.startDrag(0,origX,deltaHeight,origX);
		scrolling = "scrollbar";
	}
	updateAfterEvent();
}

onClipEvent (mouseUp){
	scrolling = 0;
	up.gotoAndStop(1);
	down.gotoAndStop(1);
	stopDrag();

	updateAfterEvent();
}

onClipEvent (mouseMove){
	if(scrolling == "scrollbar"){
		daTextBox.scroll = Math.round((scrollbar._y)/lineHeight + 1);
	}
	updateAfterEvent();
}

onClipEvent (data){
	loaded = true;
}

Cheers, I’ll give it a go and let you know how I get on. :slight_smile:

Hi,

I am kind of a newbie and have a question about scrolling text. I have tried to follow the code you have posted here but don’t really know how to apply it to my own file.

I have an swf with a dynamic textbox that calls simple txt files. I have created two buttons to scroll the text (one up, one down) but would like to put a slider bar between the buttons so that the user can “drag scroll” the text.

I guess my question is how to have the slider bar read the length of the text that is loaded?

I have attached the swf here so you can see what I have done so far. Both the swf and the dynamic text are loaded from another (main) swf. I have not yet created the slider bar. Should I follow Kirupa’s tutorial? That is, I should create two movie clips: one for the line and one for the dragger. Then create a blank movie clip called “slider” and place the other two MCs on it and put some code on it. I get confused about where to put code when you have movie clips inside movie clips inside movie clips . . .

Thanks for any help you can give!!