views:

543

answers:

2

Is it possible to clear a Flex flash.utils.Dictionary? I have a Dictionary that I want to clear (remove all elements).

A: 

I don't believe there is an explicit clear command.

However, you could write your own that would loop through all the keys and run this

delete dict[key]; 

Or you can just reassign

dict = new  Dictionary()
Jason W
A: 

I think this will work, but I'm not 100% sure, as you're modifying the dictionary while iterating over it:

function clear(d:Dictionary):void {
  for(var id:String in d) {
    delete d[id];
  }
}

However, I generally just create a new Dictionary whenever I need to clear one (though if it's referenced in multiple places then that might not work for you).

Herms