Skip to content

Hash, my darling.

October 6, 2006

I like AS2, it is so flexible. Unlike other very strict languages, AS2 definition of Object is “something that contain values with names”. Try to achive this simple thing in C# or similar, you need a specific “HashTable” class that knows how to handle your data and you need a certain “key-ing” method and stuff. Nop, in AS2 its the basic – Object.
If I want to craete a way to keep information about names and ages, all I need to do is to create an empty Object and add names to it:
var names:Object = new Object();
names.ron = 15;
names.betty = 34;
names.kitty = 13;
So easy.

Thats called hashing. What makes it so simple and easy to use, is the same thing that makes it downside. It’s not so clear to manage these hashing. Well, actually, by “managing” I mean extra checking for existance of a key… in the basic form.

What I’ve created is a basic implementation of hashing, called IndexedHash. Nothing fancy about it, just the fact that it has the basic 4 commands: addItem, removeItem, isExist and replaceItem. Another usefull command is “getName” to witch you can provide a value, or a reference to an object, and get its name. Its very basic, but this is the heart of the MovieClipCommander framework. Mostly not by itself….
Thre power of this class is realized when extending it. Now the basic hash is not only an implementation of “Object”, but rether hashing and storing services that are pretty complex.
MultipleHash: A combination of Object and Array, to create multiple values for a single key.
XMLHash: implement multile hash to represent an XML, witch its keys can be defined as on of the attributes.
ClassHash: Create annonimuse instances of a class you provide. With the abillity to run an init command and remove command.
CounterHash: Using Counter class to create a bounch of counters with names.
ServiceProvider: Using Class hash to manage services for a certain class at runtime.

Well, MovieClipCommander is using service provider to manage all the extentions. Pretty easy when thinking of it…

The code can be downloaded here:
hash packages


Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: