Practical jokes to play on Flash designers (part 2) - randomize TextFields
July 6th, 2007 . by polyGeekIn version 1 of the practical jokes to play on Flash designers I showed how to write a recursive function that bumps all the MovieClips on the stage at authoring time around a few pixels this way or that. Version 2 of this idea is to replace all the dynamic text in an FLA at authoring time with random characters.
| Before RND scramble | After RND scramble |
![]() |
Here’s the RND_textScramble code - download
How to use
You place this code anywhere in an FLA that will get it on the stage - at authoring time or run time, doesn’t matter if it’s buried in some nested MovieClip. That last line of code findTextFields(_root) passes a reference of the _root of the SWF to start the recursion.
If you would like to know more about the details of the recursive code then visit part 1 from yesterday.
As the code recursivly goes through all the MovieClips on the stage at authoring time it is looking to see if there is anything in mc[p] that has the .text property, i.e. TextFields. If it finds one then it passes that TextField as a reference to the randomizeText() function.
randomizeText()
The randomizeText function could be a lot simpler by just picking from any random ASCII character. But I wanted to make it a little more subtle. So it checks each character to see what ASCII range it’s in so that it gets replaced with a ASCII character in the same range. So a capitalized letter gets replaced by some other random capitol letter, numbers become other random numbers, etc.
It’s a bit tedious to test everything so there’s an else at the end to catch anything that doesn’t fit.
That’s about it. Just sit back and watch your designer friends slap their foreheads and say, “What the FRAK!?!?!?”
Note: It’s probably not a good idea to do this to someone just before you go on a vacation. :-)
Disclaimer: I accept no responsibility if you get fired for using this.
If you’d like to see a full list of the ASCII characters check this page: http://www.ascii.cl/htmlcodes.htm












