incubator-flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maurice Amsellem <maurice.amsel...@systar.com>
Subject Strange behavior of Dictionary and dynamic class
Date Thu, 06 Dec 2012 13:43:26 GMT
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 "::" .

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Dictionary.html

This limitation is probably well known of Flexers, but I thought it was worth sharing with
the community.

Regards,

Maurice Amsellem

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message