AS2 - Cycle through characters

Hi

I’m trying to do an effect where I have 3 characters (w b p) in 3 different textboxes and then each to cycle through random characters before reaching the correct one (say after 10secs), then to play a frame once completed. I can do this through loads of textboxes on the timeline, but would like to do it all in AS2. Does anyone know a good tutorial or which types of functions I would use so I can research it?

Thanks

Just a quick experiment:

function characterCycle(mcMovieClip:MovieClip, avoidCharacter:String, delay:Number):Void {
	var startTimer:Number = getTimer();
	var endTimer:Number = getTimer() + (delay * 1000);
	mcMovieClip.onEnterFrame = function() {
		var currentTimer:Number = getTimer();
		var character:String = String.fromCharCode(Math.floor(Math.random() * (Number(122) + 1 - Number(97))) + Number(97));
		if (currentTimer >= endTimer) {
			delete this.onEnterFrame;
			character = avoidCharacter;
		} else if (character == avoidCharacter) {
			var character:String = String.fromCharCode(Math.floor(Math.random() * (Number(122) + 1 - Number(97))) + Number(97));
		}
		mcMovieClip.textBox.text = character;
	};
}
characterCycle(mcBox1, "w", 10);

How does it work? The characterCycle function accepts three arguments; a movieclip instance name, the character you don’t want displayed until the cycle completes, and the delay in seconds before this character is finally displayed. It assumes that your movieclip contains a dynamic textfield called textBox.

The function first creates two variables, startTimer, which calculates how long the movie has been running and endTimer, which calculates a future time based on the delay argument. Next it triggers an onEnterFrame with your movieclip so that it continually updates the remaining code.

This code assigns the current time to currentTimer and creates a random character within a minimum/maximum range of 97 - 122. These represent the unicode lowercase characters. If you want to change it to include uppercase characters, change the lower number to 65. To include numerals and punctuation, change the numbers to 33 and 126. The code then checks to see if currentTimer exceeds the endTimer value. If it does, it deletes the onEnterFrame handler and inserts final desired character. If not, it recreates the random character. Finally, it assigns the value of this random character to the textBox textfield.

All you need to do is create the initial movieclip containing the textBox textfield. Then copy three instances to your stage and give them three different names. Finally, call the function for each of the boxes remembering to change the three arguments:

characterCycle(mcBox1, "w", 10);
characterCycle(mcBox2, "p", 5);
characterCycle(mcBox3, "b", 3);