First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
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){

			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;

}
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 patrickmineault@sympatico.ca.

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!

Comments

  • 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: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.