0

I want to iterate over the keys in a dictionary and I've looked at:

Efficient looping through AS3 dictionary

I am populating an dictionary using the following code:

arguments = new Dictionary();
for each(var entry:XML in bean.child("entry"))
{
    var key:String = entry.@key.toString();
    value = instantiate(entry.children()[0]);
    arguments[key] = value;
}

the 'arguments' dictionary then gets passed to another method which attempts to iterate over the keys in that array:

for (var key:Object in arguments)
{
    retval[key] = arguments[key.toString()];
}

No matter what I do with these loops, I cannot get the body of the second loop to execute.

I've verified with the debugger that 'arguments' contains the correct entries.

Community
  • 1
  • 1
spierepf
  • 2,774
  • 2
  • 30
  • 52

2 Answers2

0

I tried some test code:

private function createDict():void {
    var dict:Dictionary = new Dictionary();

    for (var j:int = 0; j < 5; j++) {
        dict[j.toString()] = new Sprite();
    }

    parseDict(dict);
}

private function parseDict(source:Dictionary):void {
    for (var key:Object in source) {
        trace(key + source[key].toString());
    }
}

And output:

[trace] 0[object Sprite]
[trace] 1[object Sprite]
[trace] 2[object Sprite]
[trace] 3[object Sprite]
[trace] 4[object Sprite]

So it works as expected. So you need to check, that in your "parseDict" function your dictionary still valid (maybe it corrupted somewhere). Also, check your keys - maybe problems with them.

Crabar
  • 1,829
  • 1
  • 14
  • 26
0

Should have known it would turn out to be a stupid flash trick...

for (var key:Object in this.arguments)
{
    retval[key] = this.arguments[key.toString()];
}

works fine.

spierepf
  • 2,774
  • 2
  • 30
  • 52