StringSet Class for Actionscript 3

Storyteller uses String IDs heavily, and I want to store them in collections but don’t want to risk duplicates, which is what the Set data structure is for.

Unfortunately, Actionscript 3 does not feature a set collection. So far, I was using the Dictionary class, but since it is not exactly a set, I tripped up several times because of its odd interface: myset["id1"] to ask for containment, delete myset["id"] for deletion and there’s no built in way to ask for its amount of elements.

I searched Google for collection libraries like AS3Commons and Polygonal, but they had a few shortcomings: the former does not implement builtin iteration (using the nefarious Proxy class) and the second does not support a set of String out of the box nor builtin iteration.

Since I don’t want to worry about sets in my game, I made my own StringSet class that has several features:

  • It is pretty type safe because it uses the String type explicitly everywhere (unlike AS collections, in which the push method traded safety for versatility).
  • Is implemented using Dictionary, which is pretty fast when asking for containment.
  • Can be iterated using for..in and for each…in, and can ask for containment using the in operator (ie if(“mydog” in dogset){}).
  • Provides several convenience methods like joining, intersection, clone, toArray, toVector, etc.
  • Caveat: it does NOT retain the order in which keys were added.
  • Caveat: may have bugs. Report them on the comments so I can fix them!
  • Download StringSet.as


hey the link dosnt work


Polarbear, I just tried it, and the link woes work, it does now anyway


really werid i guess it just dosnt like my computer


Is the game supposed to appear or file info and statistics?