Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear a Flex ActionScript Dictionary

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

like image 384
Steve Kuo Avatar asked Mar 10 '10 17:03

Steve Kuo


2 Answers

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()
like image 107
Jason Avatar answered Sep 23 '22 11:09

Jason


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:* 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).

like image 33
Herms Avatar answered Sep 21 '22 11:09

Herms