Actionscript collections

This guy implemented HashMap among other things.  Looks like you just have to cut and paste the listings to get it.

The real problem is, you should be able to iterate over an associative array and get it’s values using array syntax.  I don’t want to call HashMap.put(key, object) and HashMap.get(key) every time.  I want to create an object declaratively like

var foo:Object = {myKey:myObject, anotherkey:anotherObject};

I then want to pass the keys to a dataProvider with foo.getKeys() or retrieve data with foo[‘mykey’].

I tried creating tacking a function onto the prototype

Object.prototype.getKeys = function(){
  var keys:ArrayCollection = new ArrayCollection();
  for each (key in this)
  return keys;

But that didn’t seem to work.  (obviously we don’t want to add getKeys() to Object, so I’d create a class that extends Object, only I can’t find out an easy way to pass the literal instantiation

{myKey:myObject, anotherkey:anotherObject};

to the base Object.

Here’s another rant about actionscript and collections:

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 )

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