In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: String Blur

Get Adobe Flash player
by makc3d 16 Mar 2009
// forked from Kay's String Blur
package {
	import flash.display.*
	import flash.events.*
	import flash.filters.*
	import flash.geom.*
	import flash.media.*
	import flash.text.*
	import flash.net.*
	import flash.utils.*
	[SWF(backgroundColor=0x000000, width=400, height=400, frameRate=40)]
	public class Take01 extends Sprite {
		private const SW:Number = stage.stageWidth;
		private const SH:Number = stage.stageHeight;
		private var bitmapData:BitmapData = new BitmapData (SW, SH, true, 0);
		private var fBlur:BlurFilter = new BlurFilter (8, 0, 1);
		private var point:Point = new Point(0,0);

		private var ct:ColorTransform = new ColorTransform (1, 1, 1);
		private var bitmapDataN:BitmapData = new BitmapData (10, 10, false, 0);
		private var bitmapDataT1:BitmapData = bitmapData.clone ();
		private var bitmapDataT2:BitmapData = bitmapData.clone ();
		private var bitmapDataT3:BitmapData = bitmapData.clone ();
		private var scaleMat:Matrix = new Matrix (SW / bitmapDataN.width,
			0, 0, SH / bitmapDataN.height);
		private var offsetMat:Matrix = new Matrix (1, 0, 0, 1,
			SW/2, SH/2);
		private var textMat:Matrix = new Matrix;
		private var textAngle:Number = 0;

		private var s:Sound;
		private var ba:ByteArray = new ByteArray ();

		public function Take01():void {
			var tFormat:TextFormat = new TextFormat();
			tFormat.size = 60;
			tFormat.font = "Arial Black";
			tFormat.color = 0xffffff//0000cc;
			var tField:TextField = new TextField();
			tField.defaultTextFormat = tFormat;
			tField.selectable = false;
			tField.autoSize = TextFieldAutoSize.LEFT;
			tField.text = "wonderfl";
			offsetMat.tx -= tField.width/2;
			offsetMat.ty -= tField.height/2;
			bitmapDataT2.draw (tField, offsetMat);

			addEventListener(Event.ENTER_FRAME, rotate);

			graphics.beginBitmapFill(bitmapData);
			graphics.drawRect(0,0,SW,SH);
			graphics.endFill();

			var w:Sprite = new Sprite;
			w.graphics.beginBitmapFill(bitmapDataT3);
			w.graphics.drawRect(0,0,SW,SH);
			w.graphics.endFill();
			addChild (w);

			s = new Sound (); s.addEventListener (Event.COMPLETE, completeHandler);
			s.load (new URLRequest ("http://www.helpexamples.com/flash/sound/song3.mp3"),
				new SoundLoaderContext (1000, true));
		}

		private function rotate(e:Event):void {
			// and now, for something completely different...
			var sc:Number = 0.3;
			SoundMixer.computeSpectrum (ba, true);
			for (var k:int = 0; k < 5; k++)
				sc += Math.abs (ba.readFloat ()) * 0.6;

			ct.redMultiplier   = 0.5 + Math.abs (ba.readFloat ());
			ct.greenMultiplier = 0.5 + Math.abs (ba.readFloat ());
			ct.blueMultiplier  = 0.5 + Math.abs (ba.readFloat ());

			textAngle += 0.1; if (textAngle > 2 * Math.PI) textAngle -= 2 * Math.PI;

			textMat.identity ();
			textMat.translate (-SW/2, -SH/2);
			textMat.scale (sc, sc);
			textMat.rotate (textAngle);
			textMat.translate (+SW/2, +SH/2);

			bitmapDataN.noise (256 * Math.random (), 1, 255, 7, true);
			bitmapDataT1.draw (bitmapDataN, scaleMat, null, "normal", null, true);
			bitmapDataT1.copyChannel (bitmapDataT2, bitmapDataT2.rect, point,
				BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);

			bitmapData.draw(bitmapDataT1, textMat);
			bitmapData.applyFilter(bitmapData,bitmapData.rect,point,fBlur);
			bitmapData.colorTransform (bitmapData.rect, ct);

			bitmapDataT3.fillRect (bitmapDataT3.rect, 0);
			bitmapDataT3.draw (bitmapDataT2, textMat, null, "normal", null, true);
		}

		private function completeHandler (event:Event):void {
			// start & loop playback
			var song:SoundChannel = s.play ();
			song.addEventListener (Event.SOUND_COMPLETE, completeHandler);
		}
	}
}