Dynamic text with scrollbar

Ok I realise that this question has been asked a fair few times on this forum but having searched for a while nothing seems to answer exactly what I am looking for.

Basically I need a scroll bar which scrolls dymanically loaded text but I don’t want to use the MX UI component. If anyone can either direct me towards a tutorial on this site that I have missed, or to one somewhere else, that would be great.

Well… I have this example that I have done in F5 if you want to take a look… Go to the tutorial section of the ActionScript.org to see some of the scroller tutorials…

Cheers Pal, that’s great but…I got a similar one from actionscript.org the other day. They both work fine but neither have a scrollbar which is what I’m really after. The only other one which does have a scrollbar on actionscript.org also uses loads of other script to dynamically scale the size of the scrollbar depending on how much text is loaded in. This sounds great - and it is - but it’s way too complex for my needs and I can’t get my head round the code enough to strip out the bits I don’t need. If you have any other ideas I would be greatful.

come on…simple dynamic text scrollbar anyone?

Why not show us the code, and maybe you can get some help to sort out the codes that you don’t need??? :wink:

OK here it is, it’s from the ‘scroller 2’ tutorial on actionscript.org. If anyone has an idea why the actionscript is loaded from a seperate file I’d be interested to know that too?

come on…don’t be modest…

Okay… I just took a look at the file…

I see that most of the stuff is necessary codes… What is the portion you want to strip out???

That AS file… I sometimes use that to edit the script faster and easier…

If possible I want to strip out the part of the code that resizes the scroll bar. I just want the bare minimum of code to have a scrollbar, arrows and be able to dynamically load the content.

Try this then…

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;

//	function refreshScrollBar(){
//
//		daTextBox.scroll = resetOnNewFile ? 1 : Math.min(daTextBox.maxscroll, daTextBox.scroll);
//
//		var totalLines = numLines + daTextBox.maxscroll - 1;
//		scrollbar._yscale = 100*(numLines)/totalLines;
//		deltaHeight = origHeight - scrollbar._height;
//		lineHeight = deltaHeight/(daTextBox.maxScroll - 1);
//		scrollbar._y = lineHeight*(daTextBox.scroll - 1);
//
//	}

//	function updateScrollBarPos(){
//
//		scrollbar._y = lineHeight*(daTextBox.scroll - 1);
//	}
}

onClipEvent (enterFrame){

	if( loaded ){

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

//			refreshScrollBar();
			refreshLastMaxScroll = daTextBox.maxscroll;
			refreshCounter = 0;

		}
		refreshCounter++;
	}

	if( frameCounter % speedFactor == 0){

		if( scrolling == "up" && daTextBox.scroll > 1){
			daTextBox.scroll--;
//			updateScrollBarPos();
		}
		else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){
			daTextBox.scroll++;
//			updateScrollBarPos();
		}
		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 now

Alrighty… :wink:

Unfortunately that just seems to disable the scrollbar altogether. I wish I could offer some input from this end but I’m afraid my knowledge of AS is pretty limited at the mo. :-\

I just want the bare minimum of code to have a scrollbar, arrows and be able to dynamically load the content.
Um… I am not really getting what you are trying to do… Does the texternal file get loaded??? Is scrolling working with the up and down buttons??? Um… Is it the expanding bar in the middle??? Just get rid of it cuz you won’t be needing/using it…
Otherwise, please explain more cuz I don’t understand what is not working…

ok, this is what I’m after:

• to be able to load the text from an external text file
• to have working arrows
• to have a working scrollbar…but not a scrollbar which resizes in relation to the amount of content loaded from the external text file

cheers - d :slight_smile:

• to be able to load the text from an external text file
The script contains the text file name that you want to load… Just changing the name would be how you go about this???

• to have working arrows
I THINK the arrows are working just fine… How is it not working for you???

• to have a working scrollbar…but not a scrollbar which resizes in relation to the amount of content loaded from the external text file
I don’t understand this part at all… :frowning: How different is YOUR scroller to the original one???

Hey,

Yeah I’m fine with the scroll arrows and with loading the text from an external file, I can do that no problem. When you said before that you wanted to clarify exactly what I needed I thought I’d write the whole lot out as bullet points to make it clear, which is why I mentioned them.

The only thing I have a problem with is the scrollbar itself. I want a working scrollbar but I don’t want it to resize. This is because I think that having the scrollbar resize makes the code more complex. I want to keep the code as simple as possible as I want to be able to understand it.

Hope that makes it a little more clear. :slight_smile:

Um… I see… :wink:

So, you need the scrollbar that is a fixed size which you can drag up and down to scroll the content??? I can’t really imagine much of the code changes with that though… Hm… The only difference I think think of without actually trying it would be having a couple of less lines in the function refreshScrollBar, of course abit different login though…

Yeah that’s exactly what I want. I’ve tried deleting some of the ‘refresh scrollbar’ bits of code but I don’t really know enough about certain parts of the code to be able to do it effectively. I usually just disable the whole thing or seem to make the scrollbar draggable over the entire screen…which doesn’t seem to help much.:beam: I’ll keep tryin’ though. :smirk:

Um… This is the part that I don’t understand… There is perfectly working code in that example and you want to replace its functionality with the different code to make sure you can understand what that code is doing to your scroller, right??? Usually it is a good idea to rewrite the code to learn different approaches to the same effect, but I am not sure if the same thing applies to this case… It is totally different story if you want to have something else going on, but it is not… Hm… Why do you go over all the trouble rewriting the code??? Why not just try to understand what the existing code does??? I think that will be faster… :wink: