Thanks for your replies, I think I can probably use either Object or
Dictionary as I know my keys are always Strings.

However this raises another question, namely what do these iterators
iterate through, the keys or the objects?

In old Java speak I have a Map<String, Dog> map;

if I say 

for each (* in map)

am I iterating through the Strings or Dogs?

Thanks for your patience.  Given that Dictionary and Object seem to
support Map style operations, any idea why there is no formal Map
object in AS3 which would make this less obfuscated?

Simon

--- In [email protected], "ben.clinkinbeard"
<[EMAIL PROTECTED]> wrote:
>
> > Why a Dictionary?
> Because he was asking about HashMaps.
> 
> > As for his question about HashMaps/HashTables, Object is really the 
> > nearest equivialent.
> I would disagree, considering Dictionary supports Object keys and
> Object does not.
> 
> Ben
> 
> 
> --- In [email protected], "reflexactions" <reflexactions@>
> wrote:
> >
> > Why a Dictionary?
> > 
> > A Dictionary was designed for Object keys not realy String keys.
> > 
> > A plain old fashioned Object will surely do just fine for him, ie 
> > exactly as he had it in the first place the only thing he was missing 
> > was how to loop over the keys, which would just be:
> > 
> > for(key:String in map)map[key]
> > 
> > As for his question about HashMaps/HashTables, Object is really the 
> > nearest equivialent.
> > 
> > Dictionary should be used where you keys are themselves Objects, like 
> > a Dictionary with data rows as keys and the value being a component 
> > 
> > 
> > 
> > 
> > 
> > 
> > --- In [email protected], "ben.clinkinbeard" 
> > <ben.clinkinbeard@> wrote:
> > >
> > > Hi Simon,
> > > 
> > > Dictionary will work for you. Strings are passed by value, so it
> > > doesn't matter if you have the same key var or not. Run this code to
> > > see an example.
> > > 
> > > var d:Dictionary = new Dictionary();
> > > var s1:String = "foo";
> > > var s2:String = "foo";
> > > d[s1] = "bar";
> > > trace(d[s2]);
> > > 
> > > As for what to use as the iterator, that depends on what your
> > > collection is holding. If you don't know, or it holds more than one
> > > type of object, Object or * would be the type of your iterator. If 
> > you
> > > know you have a collection of Dog instances, use a Dog iterator.
> > > 
> > > HTH,
> > > Ben
> > > 
> > > 
> > > --- In [email protected], "simonjpalmer" <simonjpalmer@>
> > > wrote:
> > > >
> > > > thanks, sorry to be dim, but what exactly do I put as the 
> > iterator in
> > > > these loops?
> > > > 
> > > > for each (<what> in map)
> > > > 
> > > > Can I use...
> > > > 
> > > > var o:Object;
> > > > for each (o in map)?
> > > > 
> > > > Incidentally I don't think a Dictionary works in my particular
> > > > instance because it uses the strict equality === operator which 
> > means
> > > > that I can only retrieve items if I have the exact same object 
> > that I
> > > > used as the key.
> > > > 
> > > > In my case I am using a String UID value as the key so I can look 
> > up
> > > > objects from the map from lots of different places.  I can 
> > guarantee
> > > > that I will *not* have the same instance of the key object when I 
> > look
> > > > up the right hand side of the map, instead I have a String which
> > > > contains the same characters as the original key.  
> > > > 
> > > > So == will work, but === will not, which unfortunately makes the
> > > > Dictionary object useless for my purposes.
> > > > 
> > > > Simon
> > > > 
> > > > --- In [email protected], "ben.clinkinbeard"
> > > > <ben.clinkinbeard@> wrote:
> > > > >
> > > > > for...in and for...each will both work on Object but what you're
> > > > > really looking for is Dictionary. Dictionary supports those 
> > loops as
> > > > well.
> > > > > 
> > > > > HTH,
> > > > > Ben
> > > > > 
> > > > > 
> > > > > 
> > > > > --- In [email protected], "simonjpalmer" 
> > <simonjpalmer@>
> > > > > wrote:
> > > > > >
> > > > > > In the absence of a formal Map I am using an object as a 
> > key/value
> > > > > > pair map as follows:
> > > > > > 
> > > > > > var map:Object = new Object();
> > > > > > map["A"] = some_object_A;
> > > > > > map["B"] = some_object_B;
> > > > > > map["C"] = some_object_C;
> > > > > > 
> > > > > > and then looking up by the key
> > > > > > 
> > > > > > var object_A:Object = map["A"];
> > > > > > 
> > > > > > etc.
> > > > > > 
> > > > > > This works really well for random lookup by the key, but what 
> > I also
> > > > > > need is a way to iterate through the objects I have put on 
> > the map
> > > > > > object.  
> > > > > > 
> > > > > > Is there a for each(* in map) construct I can use?  
> > > > > > 
> > > > > > Does anyone know if there are any plans to support HashMaps in
> > > AS3 or
> > > > > > flash?  Is there anything synonymous to a HashMap already 
> > that I am
> > > > > > clearly not aware of?
> > > > > > 
> > > > > > Thanks
> > > > > > Simon
> > > > > >
> > > > >
> > > >
> > >
> >
>


Reply via email to