Encode/Decode (Flash MX)

Just an experiment that helped me work around an issue in a project I was working on.

This is a method of taking a string, using the character codes, converting them to hexadecimal notation so that they are all two digits long (instead of some two and some three) and then decoding that string of numbers and letters on the other side. In the sample here I just hooked some text boxes and buttons up to the functions, but the idea is to integrate these functions into other applications.
[AS]function encode(name) {
codeArray = new Array();
for (i=0; i<name.length; i++) {
code01 = name.charCodeAt(i);
codeValue = code01.toString(16);
codeArray* = codeValue;
encoded = codeArray.join("");
function decode(codeNumbers) {
decodeArray = new Array();
for (i=0; i<codeNumbers.length; i += 2) {
codeNum = codeNumbers.substr(i, 2);
codeTrue = parseInt(codeNum, 16);
decodeArray[i/2] = codeTrue;
originalArray = new Array();
for (i=0; i<decodeArray.length; i++) {
originalArray* = String.fromCharCode(decodeArray*);
originalString = originalArray.join("");
This probably isn’t the best approach for large blocks of data because it doubles the number of characters, but it works great for small pieces of information.

This isn’t hack proof encryption or anything like that, but perhaps a solution to some annoying problems. For example, the ubiquitous ampersand problem when loading variables into a Flash movie. You can search and replace ampersands or, since you’ll have to scan all the text anyways, just convert it to this encoded string and back again - ampersands come through without incident.

Or there may be times when certain characters will interfere with a database functioning but you don’t want to (or for some reason can’t) restrict the characters people use when they input information.

Or you just might want to use it for aesthetic reasons - sending data through a URL in an “encoded” format (for example in an email to a friend link that has this string of letters and numbers instead of raw data sitting in the URL).

You can probably think of other uses too.