MXMLC WTF (8): Keys can be of any type as long as it’s String
Have you ever tried looping over all the keys in a Dictionary? The whole point of the Dictionary class is that you can have objects of any type as keys, unfortunately someone forgot to tell the ActionScript compiler that:
var dict : Dictionary = ...;
for ( var k : MySpecialType in dict ) { trace(k, dict[k]); }
Error: Implicit coercion of a value of type String to an unrelated type
WTF?
2008-07-24 at 11:03
Unfortunately a side-effect of Flash.utils.Proxy:
nextName(index:int):String;
-Josh
2008-07-24 at 21:59
It looks like you want to use a “for each” loop.
2008-07-25 at 08:45
@Robert
I think it’s pretty obvious that I’m talking about looping over the keys of dictionaries, for-each loops are for looping over the values.
@Josh
Good spotting, that must be the root of the issue. This means that the error is not in the compiler but in the Flash API, or a combination of both, since the compiler has to be aware of flash.utils.Proxy.
2008-07-25 at 16:07
Sorry, I misunderstood. So how did you get around this issue? Did you type k as Object or *?
2008-07-25 at 16:38
I type as * it saves me from casting. It’s not a common issue, but an annoying one.
2008-09-10 at 08:51
On further messing about, it seems it’s not the API’s fault, but MXMLC. It isn’t smart enough to know that subclasses of Object can only be indexed by QNames except Dictionary.