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

live coding test

Get Adobe Flash player
by 9re 18 Feb 2010
/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ktF0
 */

package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.Event;
	import flash.text.TextField;
	import caurina.transitions.Equations;
	
	[SWF(backgroundColor="#000000", frameRate="50")]
    public class FlashTest extends Sprite {
       protected var tf:Text = new Text;
       private const MAX_CONST:int = 240;
       private var _counter:int = 0;
       private var _max:int;
       private var _str:String = 'live coding, hello world!!\n';
       private var _delay:int = 4;
       
       public function FlashTest() {
            // live test
            // chat feature to be implemented...(sorry!! :(
            _max = _str.length * _delay + MAX_CONST;
            
            //tf.appendText(_str);
            tf.x = 50;
            tf.y = 200;
            addChild(tf);
            
            
            addEventListener(Event.ADDED_TO_STAGE, init);
            addEventListener(Event.ENTER_FRAME, update);
        }
        
        private function init(e:Event):void {
        		//tf.appendText(e.type + '\n');
        }
        
        private function update(e:Event):void {
        		var s:String;
        		var i:int, j:int, k:int;
        		var len:int = _str.length;
        		if (++_counter == _max) {
        			removeEventListener(Event.ENTER_FRAME, update);
        		} else {
        			s = '';
        			for (i = 0; i < len; ++i) {
        				j = _str.charCodeAt(i);
        				k = _counter - i * _delay;
        				k = (k < 0) ? 0 : k;
        				k = (k > MAX_CONST) ? MAX_CONST : k;
        				s += String.fromCharCode(roundToGraphicCharacter(easeInQuad(k, j + 100, -100, MAX_CONST) - 0x21));
        				
        			}
        			tf.text = s;
        		}
        		
        }
        
        private function roundToGraphicCharacter(value:int):int {
        		var bound:int = 0x7f - 0x20;
        		value %= bound;
        		
        		return 0x21 + value;
        	}
        
        private function easeInQuad($time:Number, $beginVal:Number, $changeVal:Number, $duration:Number):Number {
        		return Equations.easeInQuad($time, $beginVal, $changeVal, $duration);
        }
    }
}

import flash.text.TextFormat;
import flash.text.TextField;
class Text extends TextField {
	private var tf:TextField;
	public function Text() {
		defaultTextFormat = new TextFormat('_typewriter', 24, 0xffffff, true);
	}
	
	override public function set text(value:String):void {
		super.text = value;
		this.adjustSize();
	}
	
	override public function appendText(value:String):void {
		super.appendText(value);
		this.adjustSize();
	}
	
	private function adjustSize():void {
		width = textWidth + 4;
		height = textHeight + 4;
	}
}