- Home
- Tutorials
- Flash
- Intermediate
- Scrolling Text (dynamic/static/loaded and HTML)

Page 2 of 3
Now that you are all looking at the same scenario let's observe how it works. First let's look at the simplest example (you can make a sample of this if you like but it isn't necessary). If I had a text field which stored the variable 'text' which maybe 10 lines and I wanted to have a button which scrolled down through that text, as stated earlier I can use the .scroll element. That's great you think, but how? Well I'll show you how. The .scroll element is used infix (you give it a path first) and works in this manner:
_root.text.scroll = 2;
This code effects the root level text field which stores the variable 'text'. In the example above it will set the line in the topmost portion of the field to line 2, whatever that happens to say. Note that it doesn't delete line 1 or anything serious like that, it simply moves it out of the way so now we can see line 2 (and anything below that if the text field is big enough). Similarly, take this example:
_root.text.scroll = 10;
This makes the topmost line in the field line 10 of the text. And so on the story goes. Get the hang of it? So if I want to show the next line in a text field (next = this + 1) I can use this code:
_root.text.scroll = _root.text.scroll + 1;
or alternatively, this code which does the same:
_root.text.scroll += 1;
This will make the text field show the next line, provided there is a next line. If I put this code on a button and click it twice, it would show line 3 (we start on line 1, 1+1+1 = 3). If the text has only 5 lines and I click this button 6 times, it will just stay on line 5. If I click it 100 times it will just stay on line 5.
So now you can see that by somehow looping this code we can make a script which will scroll slowly through our text. This is where our Controller clip comes in. My controller in the example has 4 empty frames followed by a keyframe with this code:
if (_root.up) {
_root.text.scroll += 1;
} else if (_root.down) {
_root.text.scroll -= 1;
}
gotoAndPlay (1);
Assuming you know about variables and paths, this code checks (each time this frame is reached) whether the variable up or the variable down is true and then changes the .scroll element of our text field accordingly. It also sends the controller clip back to Frame 1, which then plays through to Frame 5 and effects an infinite loop. So why the 4 blank frames? I could easily have made this a 2 frame MC or used onClipEvent (frameEnter) but this would make the .scroll element change every frame. If you are running your movie at the standard of 12 frames per second, that's 12 lines you'll scroll through each second, making it a bit difficult for the end-user to read the text before it's scrolled off the screen. You can increase or decrease the number of empty frames as per your liking.
