Letter Cycling
        Manny Dimatulac aka Thoripes

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:

  1. First, create a Movie Clip symbol and call it "letter1".
  2. Next, select the text tool, and create a box (within the symbol, of course).
  3. Now, while the cursor is still blinking look for the panel called "Text Options" (Window > Panels > Text Options).
  4. Select Dynamic Text from the drop-down menu.
  5. In the "Variable" box, type in "letter2".
  6. Change the font accordingly if you'd like in the Character panel.
  7. Now, type in any letter in the textbox for reference.
  8. Create a movie clip symbol and call it "text".
  9. With your library open, drag "letter1" onto the symbol and center it.
  10. Drag this symbol to the stage.
  11. Now for the actionscripting: Right click "letter1" and choose Actions. The Actions window will appear. Insert the script in the following text box exactly as it's typed (copy and paste) into your Actions window:

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"




kirupa.com's fast and reliable hosting provided by Media Temple.