code:
fall = function (target, weather) {
// target - where the leaves are falling. weather - frequency (msec)
target.weather = weather;
//right bottom corner of the stage
target.br = {x:Stage.width-target._x, y:Stage.height-target._y};
// array of the leaves
target.lfs = [];
target.fallLf = function(index) {
if (index == undefined) {
var index = this.lfs.length;
} else {
clearInterval(this.lfs[index]);
}
var neo = this.createEmptyMovieClip("leaf"+index, index);
neo.attachMovie("leaf", "core", 3);
neo.idx = index;
neo._y = -30; //_y coordinate where the leaves appear
neo.core._xscale = 100-random(3)*10;
neo.core._yscale = neo.core._xscale;
neo._rotation = random(150);
neo.dx = random(this.br.x);
neo._x = neo.dx;
neo.amp = {x:(1+random(25))*10}; //Amplitude _x
neo.amp.scale = Math.PI/2*(1+random(3));
neo.onEnterFrame = function() {
if (this._y-3<430) { //Bottom line where the leaves disappear
var ph = this._y/this._parent.br.y*this.amp.scale;
var cs = Math.cos(ph);
this.core._xscale = 30+Math.abs(70*cs);
this._x = this.dx+this.amp.x*cs;
this._y += 3; //Speed of fall. Try to change this value
} else {
clearInterval(this._parent.id);
var id = setInterval(this._parent, "fallLf", this._parent.weather, this.idx);
this._parent.lfs.splice(this.idx, 1, id);
removeMovieClip(this);
}
};
this.lfs.splice(index, 1, neo);
return neo;
};
target.fallLf();
target.id = setInterval(target, "fallLf", weather);
};
fall(this, 500); //Try to change this frequency to change amount the leaves on a stage