我可能正在做一些非常愚蠢的事情,但我不明白为什么下面的代码不起作用......
在这里,我创建了一个名为 spellbook 的通用对象:
// A list of all the player's spells
public var spellBook:Object = {};
在这里,我向法术书添加了一个键值对:
spellBook["bubble"] = new BubbleSpell(spellBook);
在这里我尝试输出法术书的内容:
trace("Spells initialised. Available spells are:");
for each (var _spell:String in spellBook)
{
trace(" ", _spell, " : ", spellBook[_spell]);
}
但这是我得到的输出:
Spells initialised. Available spells are:
[object BubbleSpell] : undefined
我不明白为什么它不输出:
Spells initialised. Available spells are:
bubble : [object BubbleSpell]
??
就好像我正在迭代法术书中的值,而不是键......这是怎么回事?到目前为止我看到的所有文档似乎都表明这是迭代字典的正确方法(这是一种通用对象......)我是否需要调用一个方法来获取键而不是通用值对象?
如此迷茫!