RAIN ANIMATION WITH ACTIONSCRIPT

 

CODE EXPLANATION

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

This code creates and empty movieclip on stage

holder.maxnos =75;
holder.dropspeed=1;
var txt:MovieClip;

This part starts variables to be used in the script here maxnos gives the maximum no of clips to be attached and drop speed represents the dropping sped of the rain

for (i=0; i<holder.maxnos; i++) {
holder.attachMovie("textholder", "textholder"+i, holder.getNextHighestDepth());

//setting properities of the attached clip
txt = holder["textholder"+i];
txt._x =random(Stage.width);
txt._y =random(Stage.height);
txt._xscale = txt._yscale=random(60);

//making a string containing the letters to be attached
var txtsel:String="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrtuvwxyz";
ranvalue=random(54);

/*adding a letter at random index of the string to dynamic text field inside the attached clip*/
txt.txt_char.text=txtsel.substr(ranvalue,1);
}

 

   

This is the loop to attach movieclip "textholder" that we have exported for actionscript.Now clips named textholder1 textholder2 textholder3 etc will be attached to the empty holder.

In each loop the variblename txt is given to the i th movieclip and its properties like _xscale xpositon etc are set.

Now for adding a random text to each clip we have made a string txtsel with all alphabets and defined a variable ranvalue which may have random values from 1 to 53 in each loop.

Then the string at the point ranvalue(startindex) is added to the dynamic text field named txt_char inside the clip.The syntax for selection of the substring from the string is as shown below

field instance name=Stringname.substr(startindex,endindex);

here star index have a random value between 54 and 1 and there for start index in the above code will have a random value and different characters are attached

holder.onEnterFrame = function() {
for (i=0; i<this.maxnos; i++) {
txt = this["textholder"+i];
txt._y += txt._xscale*(this.dropspeed/100);
txt._x += Math.sin((txt._y)/5);
if (txt._y>Stage.height) {
txt._y = 0;
}
}
};

This code creates movement to the attached clips and also check the y position of each clip

<<BACK

 
 
   

©2007 flashhelp.110mb.com