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" <[EMAIL PROTECTED]>
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