Diciamo che questo e' un piccolo regalo da parte mia per le festivita' Natalizie.
Si tratta di salvare la classe che sto per postare in un file di nome Snow.as e di utilizzare l'esempio per testare l' applicazione e personalizzarla a piacere.
Snow.as
codice:
class Snow extends MovieClip{
// andr3a [ www.3site.it ] [ 18/12/2004 ]
// VARIABLES
private var totalCrystals:Number, crystalAlpha:Number, windChange:Number, depth:Number = new Number();
private var path:Object = new Object();
private var crystalColor:String = new String();
// CONSTRUCTOR
function Snow(path:Object) {
this.path = path;
this.depth = 1;
setTotalCrystals(100);
setAlphaCrystals(80);
setWindCrystals(20);
setColorCrystals("0xFFFFFF");
}
// START APPLICATION
public function follow():Void {
createCrystals(crystalColor, crystalAlpha);
}
// PUBLIC SETTINGS
public function setTotalCrystals( totalCrystals:Number ):Void {
this.totalCrystals = totalCrystals;
}
public function setAlphaCrystals( crystalAlpha:Number ):Void {
this.crystalAlpha = crystalAlpha;
}
public function setWindCrystals( windChange:Number ):Void {
this.windChange = windChange;
}
public function setColorCrystals( crystalColor:String ):Void {
this.crystalColor = crystalColor;
}
// PRIVATE INITIALIZATION
private function createCrystals(crystalColor:String, crystalAlpha:Number):Void {
path.createEmptyMovieClip( "crystal_" + depth++, depth );
var firstMovie:MovieClip = path["crystal_" + (depth-1)];
with ( firstMovie ) {
beginFill( crystalColor, crystalAlpha );
moveTo( 0, 0 );
curveTo( 4, 0, 4, -4 );
curveTo( 4, -8, 0, -8 );
curveTo( -4, -8, -4, -4 );
curveTo( -4, 0, 0, 0 );
endFill();
}
for(var a:Number = new Number(depth); a<=totalCrystals; a++) {
firstMovie.duplicateMovieClip("crystal_" + depth++, depth, this);
path["crystal_" + (depth-1)]._x = path["crystal_" + (depth-1)]._width + (((Math.random()*10)*Stage.width) / path["crystal_" + (depth-1)]._width);
path["crystal_" + (depth-1)]._y = path["crystal_" + (depth-1)]._height + (((Math.random()*10)*Stage.height) / path["crystal_" + (depth-1)]._height);
path["crystal_" + (depth-1)]._xscale = path["crystal_" + (depth-1)]._yscale = (Math.random()*100);
crystalMovement(path["crystal_" + (depth-1)]);
}
firstMovie._visible = false;
}
private function crystalMovement(who:MovieClip):Void {
who.rememberWhere = new Number(0);
who.remembered = new Number(windChange+1);
who.onEnterFrame = function() {
if( this.remembered > windChange ) {
var casuality:Number = new Number((Math.random() * 100) > 50 ? 1 : -1);
this.rememberWhere = ((Math.random()*2) * casuality);
this.remembered = 0;
}
this.remembered++;
this._x += this.rememberWhere;
this._y += this._xscale / 40;
if(this._y>Stage.height) {
this._y = 0;
}
if(this._x>Stage.width) {
this._x = 0;
}
else if(this._x < 0) {
this._x = Stage.width;
}
}
}
}
esempio.fla
ricordate di settare il classpath o di mettere il fiel Snow.as nella stessa dir di questo file .FLA
codice:
// primo keyframe delle actions, mettete lo sfondo nero al documento e magari un framerate a 30 o 50 ...
// EXAMPLE 1 [ all modifying parameters ]
// DECLARATION
var mySnow:Snow = new Snow(this);
// MAKE MODIFY
mySnow.setTotalCrystals(200); // default 100 - crystals's max number
mySnow.setAlphaCrystals(60); // default 80 - crystals's alpha
mySnow.setWindCrystals(30); // default 20 - wind's change
mySnow.setColorCrystals("0xEFEFEF"); // default 0xFFFFFF - crystals's color
// DRAW & FOLLOW
mySnow.follow();
// ctrl+invio :-)
/* EXAMPLE 2 [ simple to try ]
var mySnow:Snow = new Snow(this);
mySnow.follow();
*/
Spero sia stata cosa gradita, buone feste a tutti