Christmas Booyah!

Here’s my first real experiment with the new classes introduced in Flash 8. Completely dynamic:


import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.filters.GlowFilter;
this._quality = "LOW";
Stage.scaleMode = "noScale";
var tempGlow:GlowFilter = new GlowFilter(0xCC0000, 100, 5, 5, 3, 3, true, false);
var glow:GlowFilter = new GlowFilter(0xFFFFFF, 100, 5, 5, 3, 1, false, false);
var msg:TextField = this.createTextField("msg", this.getNextHighestDepth(), 0, 0, 0, 0);
msg.autoSize = true;
msg.text = "Merry Christmas";
msg.filters = [tempGlow];
var fmt:TextFormat = new TextFormat();
fmt.font = "Times New Roman";
fmt.size = 72;
fmt.bold = true;
fmt.color = 0x990000;
msg.setTextFormat(fmt);
var ground:BitmapData = new BitmapData(msg._width, msg._height, true, 0);
ground.draw(msg);
delete fmt;
delete tempGlow;
msg.removeTextField();
var g:MovieClip = this.createEmptyMovieClip("g", this.getNextHighestDepth());
g._y = 200;
g._x = 4;
g.attachBitmap(ground, 0);
onEnterFrame = function () {
	var s:MovieClip = this.createEmptyMovieClip("s" + this.getNextHighestDepth(), this.getNextHighestDepth());
	s._x = Math.random() * Stage.width;
	s.lineStyle(2, 0xFFFFFF, 100);
	s.lineTo(1, 0);
	s.filters = [glow];
	s._xscale = s._yscale = Math.floor(50 + Math.random() * (150 - 50));
	s.matrix = new Matrix();
	s.i = 0;
	s.onEnterFrame = function() {
		if (this._y < Stage.height) {
			this._y += this._xscale / 50;
		} else {
			this.removeMovieClip();
		}
		this.i += this._xscale / 2000;
		if (this._x > Stage.width) {
			this._x = 0;
		} else if (this._x < 0) {
			this._x = Stage.width;
		} else {
			this._x += Math.sin(this.i) + ((_xmouse - (Stage.width / 2)) / 100);
		}
		if (ground.hitTest(new Point(ground.rectangle.x + g._x, ground.rectangle.y + g._y), 255, new Point(this._x, this._y))) {
			this.matrix.translate(this._x - g._x, this._y - g._y);
			ground.draw(this, this.matrix);
			this.removeMovieClip();
		}
	};
};

And the example (which apparently isn’t a valid image so it’s hosted at image-shack), low quality / [URL=“http://img507.imageshack.us/my.php?image=snow8en.swf”]high quality. It may be a bit processor intensive (especially in the browser) so I can post one that isn’t as such if it becomes unbearable.

Comments and suggestions are always welcome. Enjoy and happy holidays :hoser:.

Object-oriented version attached :).