Hi,
ActionScript converts HashMap to ArrayCollection. You can use
ArrayCollection's built-in methods to access the key/value combination. Here
is a class that I had made...
package
{
import mx.collections.ArrayCollection;
import mx.collections.IViewCursor;
import mx.collections.Sort;
import mx.collections.SortField;
public class HashMapUtil
{
public static function getValue(arrayCollection:ArrayCollection,
key:String):String{
var sf:SortField = new SortField;
sf.name = "key";
sf.numeric = false;
var sort:Sort = new Sort;
sort.fields = [sf];
arrayCollection.sort = sort;
arrayCollection.refresh()
var icur:IViewCursor = arrayCollection.createCursor();
var result:Boolean = icur.findAny({"key":key});
if (result)
return icur.current.value;
else
return "";
}
}
}
Suppose if my ArrayCollection is like this:
var arr:ArrayCollection = new ArrayCollection;
arr.addItem({"key":"India","value":"New Delhi"});
arr.addItem({"key":"USA","value":"Washington"});
arr.addItem({"key":"Pakistan","value":"Islamabad"});
arr.addItem({"key":"England","value":"London"});
To access a key-value pair, call the static method getValue like this:
trace(HashMapUtil.getValue(arr,"India"))
Let me know if you are facing any other issues.
Regards,
Venkat
www.venkatv.com
On Thu, Jan 8, 2009 at 9:02 PM, shaik firoz <[email protected]> wrote:
> I want to convert Java's HashMap to Flex supported object.
>
> I have hashmap in java like
> hashmap<k,v> = hashmap<"CA","California">
>
> i want the same thing at flex side . like in java as follows
> hashmap.get("CA") --> California.
>
> Plz help me.
>
> Thanks in advance
>
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---