- Home
- Tutorials
- Flash
- Intermediate
- Scrolling a text box

Page 3 of 3
Patrick Mineault
Freelancer behind 5 1/2 math and physics enthusiast Patrick has a knack for making seemingly simple things overly complicated. Perfect for a tutorial writer.
View all articles by Patrick MineaultRefining the script
There is one major flaw in our script right now: we can't control the speed of the scrolling. For example, if the movie is set at 30 frames per second, then we scroll 30 lines a second! That's way too much. We have to find a way to skip a few frames.
A good way to achieve this is keeping a counter containing the number of the frame we're on. If that counter can be divided by a certain number, then you should scroll, otherwise not.
To check if a number is divisible by another one, we can use the modulo ( % ) operator. This gives us the remainder of a division. For example, 11 % 3 = 2, since 11 divided by 3 is 3, with 2 remaining. Knowing this, if frameNumber % skipFactor is equal to 0, then we should scroll, otherwise not.
However, when we first click on a button, we should be given immediate feedback regardless of what frame we're on. By setting the frameNumber to skipFactor when a button is clicked, the next time the onClipEvent( enterFrame ) code is fired, the text box will scroll immediately. This is not a simple caprice: fast response times are vital to user experience.
Knowing this, our final script becomes:
For containerMC:
onClipEvent (load){
daTextBox = "Insert text here";
scrolling = 0;
frameCounter = 1;
speedFactor = 3;
}
onClipEvent (enterFrame){
if( frameCounter % speedFactor == 0){
if( scrolling == "up" && daTextBox.scroll > 1){
daTextBox.scroll--;
}
else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){
daTextBox.scroll++;
}
frameCounter = 0;
}
frameCounter++;
}
For the up button:
on( press ){
scrolling = "up";
frameCounter = speedFactor;
}
on( release, releaseOutside ){
scrolling = 0;
}
For the down button:
on( press ){
scrolling = "down";
frameCounter = speedFactor;
}
on( release, releaseOutside ){
scrolling = 0;
}
You now have a fully working and responsive scroller, just waiting to be used in your next project. I hope you enjoyed the tutorial and learned a few tricks here and there that you can use later. If you have any questions, or suggestions for another tutorial, please e-mail me at .
Be sure to be there for the next tutorial. We'll check out how to make a hierarchical menu.
Spread The Word
Article Series
-
Scrolling a text box
Related Articles
3 Responses to "Scrolling a text box" 
|
said this on 22 Jul 2007 3:56:51 PM CST
In Flash MX you need to a
|
|
said this on 05 Jun 2010 11:40:21 AM CST
I have a slight problem.
Any help? |
|
said this on 13 Jun 2010 9:23:28 PM CST
Are you previewing an old
|


Author/Admin)