flash on 2010-4-13

by kihon
♥0 | Line 47 | Modified 2010-04-13 22:22:36 | MIT License
play

ActionScript3 source code

/**
 * Copyright kihon ( http://wonderfl.net/user/kihon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Sbp
 */

package
{
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.events.Event;
	import org.libspark.betweenas3.BetweenAS3;
 
	public class Main extends Sprite
	{
		public function Main()
		{
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function onEnterFrame(event:Event):void
		{
			var bitmap:Bitmap = Text.textToBitmap(Text.createTextField(String.fromCharCode("A".charCodeAt(0) + Math.random() * 26), 30, 0x0));
			bitmap.x = mouseX - bitmap.width / 2;
			bitmap.y = mouseY - bitmap.height / 2;
			addChild(bitmap);
 
		BetweenAS3.serial
		(
			BetweenAS3.tween(bitmap, { alpha:0.0 }, null, 0.3),
			BetweenAS3.removeFromParent(bitmap)
		).play();
		}
	}
}
 
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
 
class Text
{
	public static function createTextField(text:String, size:int, color:int):TextField
	{
		var tf:TextField = new TextField();
		tf.defaultTextFormat = new TextFormat("_typeWriter", size, color, true);
		tf.text = text;
		tf.autoSize = "left";
 
		return tf;
	}
 
	public static function textToBitmap(tf:TextField, transparent:Boolean = true):Bitmap
	{
		var bd:BitmapData = new BitmapData(tf.width, tf.height, transparent);
		bd.draw(tf);
 
		return new Bitmap(bd);
	}
}