Ha, looks like your name object was re-parented Gordon. :-)

-TH

--- In flexcoders@yahoogroups.com, Maciek Sakrejda <[EMAIL PROTECTED]> 
wrote:
>
> Ah, that makes perfect sense. That's exactly the explanation I was
> looking for. Thanks, Alex.
> 
> -Maciek
> 
> 
> -----Original Message-----
> From: Gordon Smith <[EMAIL PROTECTED]>
> Reply-To: flexcoders@yahoogroups.com
> To: flexcoders@yahoogroups.com
> Subject: RE: [flexcoders] UIComponents as Object keys and Re-
parenting
> Date: Wed, 28 May 2008 12:20:14 -0700
> 
> An Object stores key/value pairs where the key is a String. When you
> write
> 
>  
> 
>     map[foo] = "foo";
> 
>  
> 
> the 'foo' object gets automatically converted to a String, via its
> toString() method. UIComponents have a toString() method which 
produces
> a string indicating their location in the DisplayObject hierarchy, 
and
> this changes when you reparent a UIComponent.
> 
>  
> 
> You probably want to use a Dictionary instead of an Object. A 
Dictionary
> can store key/value pairs where the key can be an object and 
doesn't get
> converted to a string.
> 
>  
> 
> Gordon Smith
> 
> Adobe Flex SDK Team
> 
>  
> 
>                                     
> 
______________________________________________________________________
__
> From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> Behalf Of Maciek Sakrejda
> Sent: Wednesday, May 28, 2008 10:19 AM
> To: flexcoders
> Subject: [flexcoders] UIComponents as Object keys and Re-parenting
> 
> 
>  
> 
> I have a UIComponent (let's call it Foo) that extends Canvas. I'm 
trying
> to track various instances of this in an Object, mapping each 
instance
> to some String metadata. However, when I re-parent a Foo instance 
(by
> adding it to a new container), or I re-parent that parent 
container, it
> seems to be treated as a completely distinct key by the Object. For
> example
> 
> var map:Object = new Object();
> 
> var foo:Foo = new Foo();
> 
> map[foo] = "foo";
> for (var key:* in map) {
> // Output is something like 'key is Foo455'
> trace("key is " + key);
> }
> var bar:Bar = new Bar();
> bar.addChild(foo);
> 
> map[foo] = "re-parented foo"
> for (var key:* in map) {
> // Output is something like 'key is Foo455', 'key is Bar211.Foo455'
> trace("key is " + key);
> }
> 
> Am I missing something? It seems like putting a reference to the 
object
> in a map should not changed when that object is re-parented. Is 
there
> any way to do what I'm looking for? What's the reasoning behind this
> behavior.
> 
> -- 
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
>


Reply via email to