// forked from ayataka's Hello World -Colorful- package { // import flash.display.*; import flash.text.*; import flash.filters.*; import flash.events.*; import flash.geom.*; // import caurina.transitions.Tweener; /** */ public class Main extends Sprite { /** * Constructor */ public function Main() { // create and add string sprites var ss:Array = createCharactersSprites("HORSEFIELD"); ss.forEach( function(item:*, index:uint, array:Array):void { // addChild( item ); if( index > 0 ) { item.x = array[index-1].x + array[index-1].width; } // if( Math.random() > 0.5 ) { item.rotation = Math.random() * 10; } else { item.rotation = Math.random() * -10; } } ); // add animation ss.forEach( function(item:*, index:uint, array:Array):void { Tweener.addTween(item, {x:item.x, y:item.y + 100, time:2.5, delay:0.3 * index, transition:"easeOutElastic" } ); } ); } /** */ private function createStringSprite( string:String):Sprite { // create format var format:TextFormat = new TextFormat(); format.size = 40; format.bold = false; format.leftMargin = 5; format.rightMargin = 5; // create filter var filter:BitmapFilter = new BlurFilter(30, 30); format.color = Math.random() * 255 << 16 | Math.random() * 255 << 8 | Math.random() * 255; // creae text field var tf:TextField = new TextField(); tf.text = string; if( format ) { tf.setTextFormat( format ); } tf.autoSize = "left"; // create bitmap data var bd:BitmapData = new BitmapData(tf.width, tf.height); bd.draw( tf ); if( bd ) { bd.applyFilter(bd, bd.rect, new Point(), filter); } bd.draw( tf ); // var sprite:Sprite = new Sprite(); sprite.graphics.beginBitmapFill( bd ); sprite.graphics.drawRect(0, 0, bd.width, bd.height); sprite.graphics.endFill(); // return sprite; } /** * * @return array of Sprite objects */ private function createCharactersSprites( string:String):Array { // var sprites:Array = new Array(); // var index:uint = 0; for(index = 0; index < string.length; ++index) { sprites.push( createStringSprite( string.charAt( index ) ) ); } // return sprites; } } } forked from: Hello World -Colorful-