snowstorm_class.as

来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 72 行

AS
72
字号
/*
  Snowstorm Class v1.1
  Oct. 29, 2002
  (c) 2002 Robert Penner
  
  The Snowstorm class manages a collection of SnowFlake objects,
  defining their limits, friction, falling speed, and wind.
  
  Dependencies: Snowflake class 
  
  Discussed in Chapter 12 of 
  Robert Penner's Programming Macromedia Flash MX
  
  http://www.robertpenner.com/profmx
  http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/

if (typeof Snowflake != "function") trace ("Error: required class Snowflake missing");


_global.Snowstorm = function (limits, friction, fallSpeed, timeline) {
	this.limits = limits;
	this.friction = friction;
	this.fallSpeed = fallSpeed;
	this.timeline = timeline;
	this.flakes = []; 
};

var SSP = Snowstorm.prototype;


///////////// PUBLIC METHODS

SSP.addFlake = function () {
	var lm = this.limits;
	var newFlake = new Snowflake (this.fallSpeed,
								  this.timeline,
								  this.flakes.length);
	newFlake.setStorm (this);
	var x = Math.randRangeF (lm.xmin, lm.xmax);
	var y = lm.ymin;
	var z = Math.randRangeF (lm.zmin, lm.zmax);
	newFlake.setZ (z);
	newFlake.setScreenXY (x, y);
	this.flakes.unshift (newFlake);
};

SSP.removeFlake = function () {
	return this.flakes.pop();
};


/////////// GETTER/SETTER METHODS

SSP.setWind = function (w) {
    this.$wind = w;
};

SSP.getWind = function () {
    return this.$wind;
};

/////////// GETTER/SETTER PROPERTIES

with (SSP) {
    addProperty ("wind", getWind, setWind);
}

delete SSP;

trace (">> Snowstorm class loaded");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?