# Dynamic text with scrollbar

**URL:** https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160
**Category:** Uncategorized
**Created:** [March 21, 2003, 5:40pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160 "2003-03-21T17:40:48Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![daveyc](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@daveyc](https://forum.kirupa.com/u/daveyc)
#### Post date: [March 21, 2003, 5:40pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/1 "2003-03-21T17:40:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 22, 2003, 8:36am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/2 "2003-03-22T08:36:58Z")

</div>

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](http://ActionScript.org) to see some of the scroller tutorials…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 22, 2003, 11:33am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/3 "2003-03-22T11:33:43Z")

</div>

Cheers Pal, that’s great but…I got a similar one from [actionscript.org](http://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](http://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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 23, 2003, 12:53pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/4 "2003-03-23T12:53:20Z")

</div>

come on…simple dynamic text scrollbar anyone?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 23, 2003, 1:10pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/5 "2003-03-23T13:10:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 23, 2003, 4:34pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/6 "2003-03-23T16:34:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 10:10am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/7 "2003-03-24T10:10:01Z")

</div>

come on…don’t be modest…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 11:25am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/8 "2003-03-24T11:25:37Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 11:34am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/9 "2003-03-24T11:34:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 11:43am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/10 "2003-03-24T11:43:56Z")

</div>

Try this then…

```auto
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;
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 11:58am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/11 "2003-03-24T11:58:35Z")

</div>

cheers I’ll give it a go now

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 12:04pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/12 "2003-03-24T12:04:43Z")

</div>

Alrighty… 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 12:17pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/13 "2003-03-24T12:17:55Z")

</div>

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. :-\

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 1:15pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/14 "2003-03-24T13:15:06Z")

</div>

> 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…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 24, 2003, 1:43pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/15 "2003-03-24T13:43:58Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 25, 2003, 9:56am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/16 "2003-03-25T09:56:39Z")

</div>

> • 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… ☹ How different is YOUR scroller to the original one???

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 25, 2003, 10:21am UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/17 "2003-03-25T10:21:25Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 26, 2003, 1:40pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/18 "2003-03-26T13:40:39Z")

</div>

Um… I see… 😉

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…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 26, 2003, 2:05pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/19 "2003-03-26T14:05:17Z")

</div>

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. 😏

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 26, 2003, 3:04pm UTC](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160/20 "2003-03-26T15:04:50Z")

</div>

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… 😉

[Next page](https://forum.kirupa.com/t/dynamic-text-with-scrollbar/16160.md?page=2)
