AS3 HashMap Update
I have updated the HashMap API to provide additional functionality which comes in handy when working with managed key / value pairs.
Additionally, I have also modified the HashMap class from an “is-a” to a “has-a” relationship as the previous version was a derivation of Dictionary, thus exposing the map and consequently causing a security breach in the API. This has been fixed as of this update as the map is now private rather than the object itself.
The original IMap interface I created was modeled loosely after operations which are typical of the Java Map interface. However I have identified additional operations which are useful when working with key / value pairs. These new operations have been implemented in the latest HashMap class and comprise all of the new methods.
Below is a list of the additional methods which have been implemented in the HashMap update:
- getValues: Retrieves all of the values assigned to each key in the specified map
- reset: Resets all key assignments in the HashMap instance to null
- resetAllExcept: Resets all key / values defined in the HashMap to null with the exception of the
specified key - clearAllExcept: Clears all key / values defined in the HashMap to null with the exception of the specified key
You can view the latest HashMap API source for the IMap interface and HashMap implementation. Each method is accompanied by a detailed example.
January 29th, 2008 at 6:39 pm
Hi,
I want to do something which should be very simple but can’t think which is the best approach.
I am populating a HashMap with keys and values and now want to pass this into a DataGrid, using the Keys in one column, and maybe massage elements in the value for the second column.
Can I ask a hand what would be the simplest way to pass the HashMap with say a String for a key and for the value and display the two columns?
Thanks
Matt
January 29th, 2008 at 8:50 pm
Spent 5 more minutes and came up with this.
———————————————————-
private function populateDataGrid():void
{
dgData = new ArrayCollection();
var keys = cache.getKeys();
var values = cache.getValues();
var noItems:Number = cache.size();
for(var i:int = 0; i