Letter and Number Rain
| Category | : Flash | Views | : 33767 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : letter-number-rain.zip | ||
| Result | : See the result | ||||
Add this code for the main timeline:
var letter_array = new Array(…);
//to create unique names later
var i = 0;
//this functions call another function inside it("nLetter") when
//the interval(70 milliseconds) happens
setInterval(nLetter, 70);
//will be called be "setInterval" after every 70 ms
function nLetter()
{
//duplicate the letterMC
duplicateMovieClip(letterMC, "letter" + i, 10 + i);
//increases i by 1
i++
}
Test your code now (Ctrl + Enter), it should work like the picture in the beginning of this tutorial.
Code Explanation
onClipEvent(load)
{
var index = Math.round(Math.random() * _root.letter_array.length - 1)
Random index for the array of characters available, this element on that index will be the character for this Movie Clip.
this.letter.text = _root.letter_array[index];
Set the textbox to the character on the letter_array.
_x = Math.round(Math.random() * 540) + 5
_y = Math.round(Math.random() * -20) - 10;
Random coordinate from this Movie Clip.
var gravity = 0.2;
In every frame we will increase the speed by this variable so it acts as gravity.
var ran = Math.round(Math.random() * 50) + 50;
Random value between 50 and 100; will be used for the alpha and scale of this Movie Clip.
_alpha = ran + 10;
_xscale = _yscale = ran;
Set the alpha and the scale.
speed = Math.round(Math.random() * 5) + 10;
This variable is the random falling speed; it ranges from 10 to 15.
rotSpeed = Math.round(Math.random() * 6) - 3;
Rotating speed between -3 and 3; if it’s negative the Movie Clip will rotate to the left and positive to the right.
onClipEvent(enterFrame)
{
On every frame.
_y += speed;
Change the position of the Movie Clip with the speed.
![]() |
![]() |
![]() |
![]() |
![]() |







