RAIN ANIMATION WITH ACTIONSCRIPT

 

CODE EXPLANATION

this.createEmptyMovieClip("holder", this.getNextHighestDepth());

This code creates and empty movieclip on stage

holder.maxdrops=600;//no of drops
var downspeed=500;//speed of the drops
var dropslop=30;//slop of the drops

This part starts variables to be used in the script here maxdrops gives the maximum no of clips to be attached and dropspeed represents the speed of the drops

//Part 1 attaching the clips with loop
for(i=0;i<holder.maxdrops;i++){
holder.attachMovie("circleclip","drop"+i,i+5);
focuseddrop=holder["drop"+i]
focuseddrop.cacheAsBitmap=true;
focuseddrop._x=random(Stage.width);
focuseddrop._y=random(Stage.height);
focuseddrop._yscale=random(100);
focuseddrop._rotation=-dropslop;
}

this is the loop to attach movieclip "circleclip" that we have exported for actionscript.Now clips named drop1 drop2 drop3 etc will be attached to the empty movieclip "holder" according to the value of i.

In each loop the variable name "focuseddrop" is given to the i th movieclip and its properties like _xscale xposition etc are set.Now for alpha I have linked it with the scaling of clips so that big drops that are nearer will have high alpha and others away will have low alpha.Thus part 1 of the code is completed now we have to make movement to the clip.For that we should make an interval to repeat a function in a certain time, so that the y position and x position of each clip can be changed to create movement

//part 2 setting an interval for motion of drops
var dropup=setInterval(movedrop,1)

This code creates an interval to repeat the function so as to change the ypositon and xposition of the clips to create movement.

//function to repeat in the interval
function movedrop(){
for(i=0;i<holder.maxdrops;i++){
focuseddrop=holder["drop"+i]
focuseddrop._rotation=-dropslop;
focuseddrop._y+=25+downspeed/focuseddrop._yscale;
focuseddrop.x+=Math.tan(dropslop);
if(focuseddrop._y>=Stage.height+20){
focuseddrop._y=random(30);
focuseddrop._x=random(Stage.width);
}
}
}

This is the function to repeat in the interval of .010 seconds as i have given in the code.Now when the code executes firstly the loop in on and for each value of i the value of xpos and y pos of the drops are modified after completing the loop again the function is repeated after .010 seconds and agian it enters the loop and so on. Here i have added a condition to check the y position of the loop i.e. if its less that > stage height the position of that drop is again set to a random y pssitionand random xposition at at top.Here you can change the speed no of drops etc by modifying the variables

BACK

 
 
 
   

©2007 flashhelp.110mb.com