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

break text

@author minon@minomix.net
Get Adobe Flash player
by minon 19 Dec 2008
    Embed
/**
 * @author minon@minomix.net
 */
package  {
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.text.*;
	
	[SWF(backgroundColor="#000000",width="465",height="465",frameRate="60")]
	
	public class App2 extends Sprite {
		
		private var _canvas:BitmapData;
		private var _source:BitmapData;
		private var _t:TextField;
		
		private var _particles:Array = new Array();
		
		private var _line:int = 0;
		private var _n:int = 1;
		
		public function App2() {
			
			_t = new TextField();
			_t.defaultTextFormat = new TextFormat( "_sans", 32, 0xFFCC00 );
			_t.autoSize = TextFieldAutoSize.LEFT;
			_t.text = "Hello World\nClick!";
			
			_source = new BitmapData( _t.textWidth, _t.textHeight, true, 0x00FF0000 );
			_source.draw( _t );
			this.addChild( new Bitmap( _source ) );
			
			_canvas = new BitmapData( 465, 465, true, 0x00FF0000 );
			this.addChild( new Bitmap( _canvas ) );
			
			this.stage.addEventListener( MouseEvent.CLICK, clickHandler );
			
		}
		
		
		private function clickHandler(e:MouseEvent):void {
			_line = _source.height;
			this.addEventListener( Event.ENTER_FRAME, breakLine );
			this.addEventListener( Event.ENTER_FRAME, update );
		}
		
		
		private function breakLine(e:Event):void {
			
			var l:int;
			for (var i:int = 0; i <= _n ; i++) {
				for (var j:int = 0; j < _source.width ; j++) {
					l = _line - i;
					if ( _source.getPixel32( j, l ) != 0 ) {
						emit( j, l, 1.05, _source.getPixel32( j, l ) );
						_source.setPixel32( j, l, 0 );
					}
				}
			}
			
			_line -= _n;
			if ( _line < 0 ) this.removeEventListener( Event.ENTER_FRAME, breakLine );
			
		}
		
		public function emit(ex:Number, ey:Number, s:Number = 1, c:int = 0xffffff ):void {
			var p:Particle = new Particle();
			p.x = ex;
			p.y = ey;
			p.xx = Math.random() * 2 + 1;
			p.yy = Math.random() / 2;
			p.s = s;
			p.c = c;
			_particles.push(p);
		}
		
		public function update(e:Event):void {
			
			_canvas.lock();
			_canvas.fillRect(this._canvas.rect, 0x00FF0000);
			var n:int = _particles.length;
			
			while (n--) {
				var p:Particle = this._particles[n];
				p.yy += 0.01 * p.s;
				p.xx *= 0.999;
				p.x += p.xx;
				p.y += p.yy;
				p.l--;
				_canvas.fillRect( new Rectangle( p.x, p.y, 1, 1 ), p.c );
				
				if ( p.y > stage.stageHeight || p.l < 0 || p.x < 0 || p.x > stage.stageWidth ) {
					this._particles.splice(n, 1);
				}
			}
			
			_canvas.unlock();
			
		}
	}
}

class Particle {
	
	public var x:Number;
	public var y:Number;
	public var xx:Number;
	public var yy:Number;
	public var s:Number;
	public var c:int;
	public var l:int
	
	public function Particle() {
		this.x = 0;
		this.y = 0;
		this.xx = 0;
		this.yy = 0;
		this.s = 1;
		this.c = 0x00FF00;
		this.l = 50 + Math.random() * 50;
	}
	
}