Ti ho aggiunto il metodo stopSnow() per bloccarla e un metodo restartSnow() per farla riprendere....
Codice PHP:
/*
==========================================================================
Properties
--------------------------------------------------------------------------
snowFlakes : Set the number of snowflakes
depth : Set the depth for the snow effect
wind : Set the windspeed
minSpeed : Set the minimum fallingspeed
maxSpeed : Set the maximum fallingspeed
minScale : Set the minimum snowflake mc scale
maxScale : Set the maximum snowflake mc scale
minAlpha : Set the minimum snowflake mc alpha
maxAlpha : Set the maximum snowflake mc alpha
rotation : Set rotation on/off
maxAngle : Set the maximum angle for rotation
parent : Set the parent (holder)
mcName : Set the linkage name of the snowflake mc
==========================================================================
Methods
--------------------------------------------------------------------------
setBoundary(minX, minY, maxX, maxY) : Set the boundary for the snow effect
startSnow() : Start the snow effect
stopSnow() : Pause the snow effect
restartSnow() : Re-start the snow effect
==========================================================================
*/
class Snow
{
// Set internal variables
private var m_stopSnow : Boolean;
private var m_snowFlakes : Number;
private var m_depth : Number;
private var m_wind : Number;
private var m_minX : Number;
private var m_minY : Number;
private var m_maxX : Number;
private var m_maxY : Number;
private var m_minSpeed : Number;
private var m_maxSpeed : Number;
private var m_minScale : Number;
private var m_maxScale : Number;
private var m_minAlpha : Number;
private var m_maxAlpha : Number;
private var m_rotation : Boolean;
private var m_maxAngle : Number;
private var m_parent : MovieClip;
private var m_mc : MovieClip;
private var m_mcName : String;
// set the number of snowflakes
public function set snowFlakes (p_snowFlakes : Number) : Void
{
this.m_snowFlakes = p_snowFlakes;
}
// set the startdepth for the snowflakes
public function set depth (p_depth : Number) : Void
{
this.m_depth = p_depth;
}
// set the windspeed
public function set wind (p_wind : Number) : Void
{
if (p_wind > 5)
{
trace ("wind can not be higher the 5");
} else if (p_wind < - 5)
{
trace ("wind can not be lower then -5");
} else
{
this.m_wind = p_wind;
}
}
// set the minimum fallingspeed (pixels per frame)
public function set minSpeed (p_minSpeed : Number) : Void
{
if (p_minSpeed > this.m_maxSpeed)
{
trace ("minSpeed can not be higher then maxSpeed");
} else if (p_minSpeed < 1)
{
trace ("minSpeed can not be lower then 1");
} else
{
this.m_minSpeed = p_minSpeed;
}
}
// set the maximum fallingspeed (pixels per frame)
public function set maxSpeed (p_maxSpeed : Number) : Void
{
if (p_maxSpeed < this.m_minSpeed)
{
trace ("maxSpeed can not be lower then minSpeed");
} else
{
this.m_maxSpeed = p_maxSpeed;
}
}
// set the minimum scale of the snowflakes
public function set minScale (p_minScale : Number) : Void
{
if (p_minScale > this.m_maxScale)
{
trace ("minScale can not be higher then maxScale");
} else if (p_minScale < 0)
{
trace ("minScale can not be lower then 0");
} else
{
this.m_minScale = p_minScale;
}
}
// set the maximum scale of the snowflakes
public function set maxScale (p_maxScale : Number) : Void
{
if (p_maxScale < this.m_minScale)
{
trace ("maxScale can not be lower then minScale");
} else
{
this.m_maxScale = p_maxScale;
}
}
// set the minimum alpha for the snowflakes
public function set minAlpha (p_minAlpha : Number) : Void
{
if (p_minAlpha > this.m_maxAlpha)
{
trace ("minAlpha can not be higher then maxAlpha");
} else if (p_minAlpha < 0)
{
trace ("minAlpha can not be lower then 0");
} else
{
this.m_minAlpha = p_minAlpha;
}
}
// set the maximum alpha for the snowflakes
public function set maxAlpha (p_maxAlpha : Number) : Void
{
if (p_maxAlpha < this.m_minAlpha)
{
trace ("maxAlpha can not be lower then minAlpha");
} else if (p_maxAlpha > 100)
{
trace ("maxAlpha can not be higher then 100");
} else
{
this.m_maxAlpha = p_maxAlpha;
}
}
// set rotation on/off
public function set rotation (p_rotation : Boolean) : Void
{
this.m_rotation = p_rotation;
}
// set the maximum angle for the ratation
public function set maxAngle (p_maxAngle : Number) : Void
{
this.m_maxAngle = p_maxAngle;
}
// set the parent movieclip
public function set parent (p_parent : MovieClip) : Void
{
this.m_parent = p_parent;
}
// set the movieclip name to use for the snowflakes
public function set mcName (p_mcName : String) : Void
{
this.m_mcName = p_mcName;
}
// initialize (set the default values)
public function Snow ()
{
this.m_stopSnow = false;
this.m_snowFlakes = 100;
this.m_depth = _root.getNextHighestDepth ();
this.m_wind = 0;
this.m_minX = 0;
this.m_minY = 0;
this.m_maxX = Stage.width;
this.m_maxY = Stage.height;
this.m_minSpeed = 1;
this.m_maxSpeed = 3;
this.m_minScale = 20;
this.m_maxScale = 100;
this.m_minAlpha = 25;
this.m_maxAlpha = 75;
this.m_rotation = false;
this.m_maxAngle = 35;
this.m_parent = _root;
this.m_mcName = "";
}
// set the boundary for the snow effect
public function setBoundary (p_minX : Number, p_minY : Number, p_maxX : Number, p_maxY : Number) : Void
{
this.m_minX = p_minX;
this.m_minY = p_minY;
this.m_maxX = p_maxX;
this.m_maxY = p_maxY;
}
// create a movieclip to use as snowflake
private function createMC (p_instance, p_depth) : Void
{
this.m_mc = this.m_parent.createEmptyMovieClip (p_instance, p_depth);
with (this.m_mc)
{
beginFill (0xFFFFFF);
moveTo (2, 0);
curveTo (3, 0, 4, 2);
curveTo (4, 3, 2, 4);
curveTo (1, 4, 0, 2);
curveTo (0, 1, 2, 0);
endFill ();
}
}
// create a movieclip to use as a mask
private function createMask () : MovieClip
{
var mc : MovieClip = this.m_parent.createEmptyMovieClip ("mask", 1000000);
mc.beginFill (0xFF0000);
mc.moveTo (this.m_minX, this.m_minY);
mc.lineTo (this.m_maxX, this.m_minY);
mc.lineTo (this.m_maxX, this.m_maxY);
mc.lineTo (this.m_minX, this.m_maxY);
mc.lineTo (this.m_minX, this.m_minY);
mc.endFill ();
return mc;
}
// start the snow effect
public function startSnow () : Void
{
this.m_parent = this.m_parent.createEmptyMovieClip ("snow", this.m_parent.getNextHighestDepth ());
this.m_parent.setMask (this.createMask ());
for (var i : Number = 0; i < this.m_snowFlakes; i ++)
{
if (m_mcName <> "")
{
this.m_mc = this.m_parent.attachMovie (this.m_mcName, "snowflake" + i, this.m_depth + i);
} else
{
this.createMC ("snowflake" + i, this.m_depth + i);
}
this.m_mc.pause = this.m_stopSnow;
this.m_mc.wind = this.m_wind;
this.m_mc.minX = this.m_minX;
this.m_mc.minY = this.m_minY;
this.m_mc.maxX = this.m_maxX;
this.m_mc.maxY = this.m_maxY;
this.m_mc.speed = this.m_minSpeed + Math.random () * (this.m_maxSpeed - this.m_minSpeed);
this.m_mc.p = Math.PI + Math.random () * Math.PI;
this.m_mc.r = 0;
this.m_mc.rotation = this.m_rotation;
this.m_mc.maxAngle = this.m_maxAngle;
this.m_mc.startAngle = this.m_mc._rotation;
this.m_mc._xscale = this.m_mc._yscale = this.m_minScale + Math.random () * (this.m_maxScale - this.m_minScale);
this.m_mc._alpha = this.m_minAlpha + Math.random () * (this.m_maxAlpha - this.m_minAlpha);
if (this.m_wind > 0)
{
this.m_mc._x = (this.m_minX - 50) + Math.random () * ((this.m_maxX - this.m_minX - this.m_mc._width) + 50);
} else if (this.m_wind < 0)
{
this.m_mc._x = this.m_minX + Math.random () * ((this.m_maxX - this.m_minX - this.m_mc._width) + 50);
} else
{
this.m_mc._x = this.m_minX + Math.random () * (this.m_maxX - this.m_minX - this.m_mc._width);
}
this.m_mc._y = this.m_minY + Math.random () * (this.m_maxY - this.m_minY - this.m_mc._height);
this.m_mc.onEnterFrame = function ()
{
if (this.pause == false)
{
{
this.r += (this.p / 180) * Math.PI;
if (this.rotation)
{
this._rotation = this.startAngle + (Math.sin (this.r) * this.maxAngle);
}
this._x -= Math.cos (this.r) - this.wind;
this._y += this.speed;
if (this._x < (this.minX - 10 - this._width))
{
this._x = this.maxX + 5;
this._y = this.minY + Math.random () * (this.maxY - this.minY - this._height);
}
if (this._x > (this.maxX + 10))
{
this._x = this.minX - 5 - this._width;
this._y = this.minY + Math.random () * (this.maxY - this.minY - this._height);
}
if (this._y > this.maxY)
{
if (this.wind > 0)
{
this._x = (this.minX - 50) + Math.random () * ((this.maxX - this.minX - this._width) + 50);
} else if (this.wind < 0)
{
this._x = this.minX + Math.random () * ((this.maxX - this.minX - this._width) + 50);
} else
{
this._x = this.minX + Math.random () * (this.maxX - this.minX - this._width);
}
this._y = this.minY - this._height;
}
}
}
}
}
}
public function stopSnow () : Void
{
this.m_stopSnow = true;
for (var i : Number = 0; i < this.m_snowFlakes; i ++)
{
this.m_parent ["snowflake" + i].pause = this.m_stopSnow;
}
}
public function restartSnow () : Void
{
this.m_stopSnow = false;
for (var i : Number = 0; i < this.m_snowFlakes; i ++)
{
this.m_parent ["snowflake" + i].pause = this.m_stopSnow;
}
}
}