【发布时间】:2011-03-11 21:31:02
【问题描述】:
我目前正在处理一个 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(名为 this.dropLocationsXML)的 ActionScirpt 代码:
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 属性?
【问题讨论】:
标签: xml actionscript-3