OK, there's already an API thread about making rain, but i believe mine's better :p.
I will put //comments inside the AS to explain what's happening, so don't get angry that i haven't explained it because i have.
Anyway i'll start off by showing you the finished result of what we will be making.
To start off, make an MC of a raindrop (fig:1) and give it the instance name rain. Try and get the shape realistic, but make the colour a solid blue.
Inside the MC type in this code:
onClipEvent (load) {
// Give a viariable a number between 0 and 850
// change the number 850 to about 300 more than the width of your stage.
xpos = Math.random()*850;
//set the raindrop to somewhere between -300 and 550 on the x axes.
this._x = xpos-300;
//set the raindrop to somewhere between -450 and 0 on the y axes.
//This is so it won't start from the same height each time it drops,
// but will always start off the screen.
this._y = Math.random()*-450;
//change tha alpha to somewhere between 0 and 60%
this._alpha = int(Math.random()*60);
// Set two variables, xspeed and yspeed.
//xspeed is always between 10 and 25
//yspeed is always 4*xspeed.
speed = Math.random()*15;
speedx = speed+10;
speedy = speedx*4;
}
onClipEvent (enterFrame) {
//Make the raindrop got downwards by yspeed each frame and accross
//by xspeed each frame.
//this is done so that it falls at an angle
this._x += speedx;
this._y += speedy;
//rotate the raindrop so that it faces the direction it falls
this._rotation = -20;
//When the raindrop reaches the bottom of the screen,
// it goes back to the top and falls again from a random spot
if(this._y>400){
this._x = xpos-300;
this._y = Math.random()*-450;
}
}
Then on the main timeline paste this code:
//Duplicate the rain movieclip 60 times
for(i=0; i<60; i++){
rain.duplicateMovieClip("rain", +i, i);
}
And hey presto, you have rain that falls randomly at a random speed and has a random alpha. You can easily mess around with it to change the speed it falls at, the alpha it has or even how much wind there is and which direction it's coming from.
This method also works well with snow.