A couple of questions on the Dictionary class in Actionscript 3:
What's the best way to check for an unused key? I'm doing
dictionary[key] == undefined
right now. Is that the fastest and cleanest way?Do I have to loop through and
delete dictionary[key]
or can I just let the dictionary go out of scope?Is there a better solution for mapping message listeners to a broadcasting class? I do something like this:
addListener(function : Function, messageType : Type) { if(dictionary[messageType] == undefined) dictionary[messageType] = new Vector<Function>(); dictionary[messageType].push(function); } broadcast(message : Message, messageType : Type) { if(dictionary[messageType] != undefined) { for each(var function : Function in dictionary[messageType]) function(message); } }
I just typed that out now, so it may not be 100% accurate. Good idea to use a routing system with a dictionary like that?