First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Patrick Mineault

Refining 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){



		else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){



		frameCounter = 0;


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;

Note: You may need to adjust the speedFactor in the load clip event. Usually, 10 lines a second is a good speed, so speedFactor should be a tenth of the FPS of your movie. speedFactor needs to be an integer, though.

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.

» Level Basic

Added: 2001-06-20
Rating: 8 Votes: 400
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.