incubator-flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maurice Amsellem <>
Subject RE: Strange behavior of Dictionary and dynamic class
Date Thu, 06 Dec 2012 18:03:53 GMT
Hi Alex, 

I gave Dictionary as an example only, sorry if this created confusion,  as  the issue actually
exists mainly for Object and any dynamic subclass, when setting a string key  (see code below).

Actually, I am not using Dictionary for storing String=> Object maps, but my own dynamic
subclass of Object.

The test below fails, and the debugger show that map contains one key "myKey" and not "myPrefix::myKey";

    public function testObjectKey():void {

        var key: String = "myPrefix::myKey";
        var map: Object = {};
        map[key] = "myValue";
        var result: Object = map[key];
        Assert.assertNotNull( "key with :: should not be null", result);


Am I doing something wrong ?



-----Message d'origine-----
De : Alex Harui [] 
Envoyé : jeudi 6 décembre 2012 18:21
À :
Objet : Re: Strange behavior of Dictionary and dynamic class

Hi Maurice, 

Strings should not be used as keys in Dictionary.

I believe that :: is a namespace delimiter.


On 12/6/12 5:43 AM, "Maurice Amsellem" <> wrote:

> Hi,
> I have noticed  a strange behavior regarding the way dynamic classes, 
> including Dictionary and Object manage keys:
> if you are using a String key and the key includes "::", then 
> everything before the "::"will be stripped from the key.
> Example:
> var dic: Object ;
> dic ["prefix::ABCD"] = "SomeValue".
> The Object will now contain:
> "ABCD" => "SomeValue";
> Instead of:
> "prefix::ABCD" =>"SomeValue";
> My intuition is that FlashPlayer does this to store Class members that are in
> a different namespace,  eg.    DataGrid.mx_internal::sortDirection,
> so that the namespace is trimmed from the variable name.
> "::" is also used as the separator between namespace and Class or 
> variable name in Qualified Names, as returned by 
> getQualifiedClassName()
> So if you use a key that includes a qualified name, obtained from
> getQualifiedClassName() or a variant, then you must replace "::" with 
> something else, before using it as a key.
> var key : String = "prefix::ABCD";
> var safeKey: String = key.replace("::","."); dic[safeKey] = value;
> Note:  Adobe documentation subtely suggests this limitation in the 
> flah.utils.Dictionary class online help:
> Note: You cannot use a QName object as a Dictionary key.
> Albeit it's true for any dynamic class, and even if the key is a 
> String including "::" .
> sh/utils
> /Dictionary.html
> This limitation is probably well known of Flexers, but I thought it 
> was worth sharing with the community.
> Regards,
> Maurice Amsellem

Alex Harui
Flex SDK Team
Adobe Systems, Inc.

View raw message