开发者

Getting a key in the ActionScript Dictionary

I am using a Dictionary in ActionScript as a queue, sort of, still reading most of the time as an associative container, but I need one time to make a loop to run through the whole dictionary, such as for (var key:String in queue) . I开发者_StackOverflownside this for loop I perform some actions on an element and then call delete on that key.

My issue is that I would like to wait for an Event before fetching the next element in this queue. Basically my for loop runs too fast. I would like to fetch the next key all the time, but I know there is no built in method.

A solution I thought is to add a break to the loop, as the for.. in will automatically fetch the next key, but it would be a loop which always executes one time, simply to fetch the next key. This sounds a bit counter intuitive.

I hope my problem makes sense and I really look for some better ideas than what I currently have. Thanks for your help!

Rudy


haha, that is an interesting problem indeed. there doesn't seem to be any way of retrieving a list of keys from the dictionary, short of the method you've outlined. an alternative would be caching the list of the keys on the first run, but that might get out of sync and is quite untidy anyway.

i guess my main question is why can't you do what you want to do with a list? if you need 2 values (eg strings) then just make a list of objects :)


var lInfo:Object = ObjectUtil.getClassInfo(lDict);
                    
for each(var lProperty:String in lInfo.properties)
{
    var lItem:* = lDict[lProperty];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜