ActionScript No Longer Sucks So Much

Oh how I hate ActionScript. I was fed up with it not having hashes, so I wrote my own hash algorithm. It's called like this:

#include "hash.as"

myHash = new Hash();

myHash.set("this key", "some value");

myHash.set("that key", randomObject);

thisText = myHash.get("that key");

Yes, I am lame. I even automatically generated documentation using my automatic documentation generator, and I have added a new section called flash, where my various exciting outings with flash will go. Please let it end here.

Comments

If it's anything like JavaScript, can't you just use objects as hash tables?

myHash = new Object();
myHash['key'] = 'value';
value = myHash['key'];

If it was anything like JavaScript you could, but alas, it's not. At least I haven't found anywhere that says it is, just lots of people saying it's not. The closest is using a variable with the name of the key, like:

set("crapHash."+key, value)
value = eval("crapHash"+key);

But that's rather annoying...

Maybe I'm missing something, but would Actionscript's associative arrays do the same thing? I hash movieclip objects into an array to look up stuff, before I realized I could just stuff the associated object into the movieclip object itself.

I may be wrong but I think associative arrays came along in MX 2004, I'm working in MX 2002.

Hashes aka objects have been around since Flash 5. Use it just like Simon Willison described

Ahh, so they have. Oh well.

Leave a comment