Created
June 15, 2012 18:43
-
-
Save mattlundstrom/2938102 to your computer and use it in GitHub Desktop.
Flash Text Descrambler
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
var randomChars:String = "A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_!_@_#_$_%_^_&_!_ _ _ _ _ _ _" | |
var charArray:Array = randomChars.split("_"); | |
function descramble(speed:int, txt:TextField):void{ | |
var originalString:String = txt.text; | |
var newFragment:String; | |
var newString:String; | |
var characterNum:int = 0; | |
function randText(len:int = 6):String | |
{ | |
var tempArray:Array = new Array(len); | |
for (var z:int = 0; z < len; z++) | |
{ | |
tempArray[z] = charArray[int(Math.random() * charArray.length)]; | |
} | |
return tempArray.join(""); | |
} | |
function onTick(event:TimerEvent):void{ | |
if (characterNum < originalString.length + 1){ | |
newFragment = originalString.slice(0, characterNum); | |
newString = newFragment += randText(originalString.length - characterNum); | |
characterNum ++; | |
txt.text = newString; | |
} else { | |
scrambleTimer.stop(); | |
scrambleTimer.removeEventListener(TimerEvent.TIMER, onTick); | |
} | |
} | |
var scrambleTimer:Timer = new Timer(speed); | |
scrambleTimer.addEventListener(TimerEvent.TIMER, onTick); | |
scrambleTimer.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment