Created
July 22, 2010 18:15
-
-
Save anthonycintron/486358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gibberish | |
{ | |
import flash.display.Sprite; | |
import flash.geom.Rectangle; | |
import flash.text.*; | |
import gs.TweenLite; | |
import gs.TweenMax; | |
public class GibberishTextField extends Sprite | |
{ | |
[Embed(source="arial.ttf", fontFamily="foo")] | |
public var bar:String; | |
public static const NUMBERS:Array = new Array(1,2,3,4,5,6,7,8,9,0); | |
public static const ALPHABET:Array = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); | |
public static const START_COLOR:String = '#51BE30'; | |
public static const END_COLOR:String = '#914CB8'; | |
public static const START_SIZE:Number = 0.2; | |
public static const END_SIZE:Number = 1; | |
public static var speed:Number = 5; | |
private var _text:String; | |
private var _textField:TextField; | |
public function GibberishTextField() | |
{ | |
super(); | |
} | |
public function get text():String | |
{ | |
return _text; | |
} | |
public function set text(value:String):void | |
{ | |
_text = value; | |
build(); | |
} | |
private var _currentRenderedText:String; | |
protected function build():void | |
{ | |
_textField = new TextField(); | |
_textField.text = _text; | |
addChild( _textField ); | |
_textField.autoSize = TextFieldAutoSize.LEFT; | |
_textField.visible = false; | |
for ( var i:int = 0; i < _textField.length; i++ ) | |
{ | |
var rect:Rectangle = _textField.getCharBoundaries(i); | |
var str:String = _textField.text.substr(i,1); | |
generateTextField( str, rect.x, rect.y, rect.width, rect.height ); | |
} | |
} | |
private function generateTextField(str:String, x:Number, y:Number, width:Number, height:Number ):void | |
{ | |
var txtFormat:TextFormat = new TextFormat(); | |
txtFormat.font = "foo"; | |
txtFormat.size = 12; | |
txtFormat.color = 0x000000; | |
var txt:TextField = new TextField(); | |
txt.autoSize = TextFieldAutoSize.LEFT; | |
txt.x = x; | |
txt.y = y; | |
txt.selectable = false; | |
txt.width = width; | |
txt.height = height; | |
txt.alpha = 0; | |
addChild( txt ); | |
txt.embedFonts = true; | |
txt.setTextFormat( txtFormat ); | |
txt.text = str; | |
animateTextFieldIn( txt ); | |
} | |
private function buildTextFormat(txt:TextField):void | |
{ | |
var txtFormat:TextFormat = new TextFormat("Arial", 12, 0xCCCCCC); | |
txt.defaultTextFormat = txtFormat; | |
addChild( txt ); | |
txt.text = _text; | |
trace(txt.text); | |
} | |
private function animateTextFieldIn( txtField:TextField ):void | |
{ | |
TweenLite.to( txtField, Math.random()*speed, {alpha:1}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creates a funky text effect from your string. Random characters sequence in. The characters fade and change colors as they come in.