This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
By the end of this tutorial, you'll be able to create a little movie that randomly selects letters and stops on the letter you want it to:
Now not to scare you, a LOT of actionscripting is involved in this project. I'll try explaining what each line means so you don't get lost.
Now before jumping to the directions, there some things you should know first. The letters and various characters on a computer are determined by a unique value. In other words, letters have a specific number, or code. Since there is no way for flash to randomly select letters, we're going to artifically make it happen. By randomly selecting numbers, which flash can do, we can use a function in flash called chr(number); which transforms the number to its corresponding letter. number in that function is replaced by a certain number pertaining to the specific letter. However, that doesn't mean 1 = "A". Letter "A" actually starts with the number 65. Do this: hold Alt, then type 65 on the keypad on the right side of the keyboard, you should get the letter "A". The numbers go in order from there. 66 = "B", 67 = "C", etc. Lowercase letters start from the number 97.
With that in mind, lets start:
onClipEvent (load) {
go = true;
}
onClipEvent (enterFrame) {
if (go) {
x = random(122);
if ((x>=65) and (x<=122)) {
this.letter2 = chr(x);
}
if (x == 65) {
// replace [number] with the number corresponding with the first letter in the word you want.
go = false;
}
}
}
Ok, lets split this badboy apart:
onClipEvent(load) - this just contains the actions to take place once the movie clip symbol is loaded
go = true; - this sets variable "go" = true, a Boolean value. You'll see why in a sec.
onClipEvent(enterFrame) - this is where all the actions take place repeatedly as long as the movie is still playing. The actions within this handler is looped every time the MC is accessed. (you notice that a movieclip symbol always loops itself unless a stop(); action is given. so the actions here are looped as well)
if (go) - referring to the "go" variable, this triggers whether or not the proceeding actions will take place. The first time, the actions will take place because "go" was given a true. So flash reads this as "if go is true, do these actions. if it's false, don't do these".
x = random(122); - this gives variable x a random number from 0 to 122. 122 is lowercase z.
if ((x >= 65) and (x <= 122)) - this sets up a range for x, cause we only want letters A-Z and a-z, not anything else. x must be greater than or equal to 65 because 65 is A; likewise, must be less than or equal to 122 because 122 is z.
this.letter2 = chr(x); - this tells flash to make the dynamic textbox equal to the letter it randomly chose from the steps above. "this" refers to itself. the ".letter2" refers to the textbox within itself.
if (x == [number]) - you want it to do these actions once it hits the letter you want.
go = false; - this sets go to false, which tells flash to stop randomly choosing letters, since it's already got it.
Now with that action in that MC, hold CTRL and drag the symbol as many times as the number of letters in the word or phrase you want to make.
Position the letters in a line, if you'd like.
Go to each letter and change [number] to the number corresponding to the letter you want.
Finally, drag "text" to the main stage and play!
If you don't happen to know the ASCII code for every single letter, upper and lowercase, in the alphabet, use the Flash utility below. Enter the letter or number you would like the code for and press the arrow. The corresponding ASCII number will be displayed.
contact: [email protected]
I'll send you the FLA if you like. e-mail me or request for it in the Flash 5 forums. my alias there is "thoriphes"
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.
Your support keeps this site going! 😇
:: Copyright KIRUPA 2026 //--