如何访问AS3中的XMLList节点

时间:2010-07-05 12:09:51

标签: xml actionscript-3

我目前正在使用XML列表,如下所示:

<feature type="startLocation" value="1" x="15" y="3"/>
<feature type="startLocation" value="1" x="15" y="4"/>
<feature type="startLocation" value="1" x="15" y="5"/>
<feature type="startLocation" value="1" x="15" y="6"/>
<feature type="startLocation" value="1" x="15" y="7"/>

这是解析此XMLList的ActionScirpt代码(名为this.dropLocationsXML):

public function dropUnit()
{
    var numX:int;
    var numY:int;
    var feature:XMLList;
    trace(this.dropLocationsXML);
    for(var i:int = 0; i < this.dropLocationsXML.length(); i++)
    {
        feature = this.dropLocationsXML.child(i);
        numX = -16 + (feature.@x)*35;
        numY = 4 + (feature.@y)*35;
    }
}

现在,当我尝试使用child()函数访问此XMLList时,我最终得到一个空的XMLList。 当我尝试使用this.dropLocationsXML [1]和valueOf()方法时,情况也是如此。
如您所见,我只需要从每个功能标签中提取x和y属性。 trace()语句给出了上面显示的XML输出 有谁知道如何访问XML列表的根节点,以便我可以使用x和y属性?

1 个答案:

答案 0 :(得分:3)

for each (var x : XML in dropLocationsXML.feature) {
    trace("xml: "+x.@type);

}
相关问题