开发者

How to access XMLList nodes in AS3

I am working with an XML list at the moment, which looks like this:

<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"/>

This is the ActionScirpt code which parses this XMLList (named 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;
    }
}

Now when I try to access this XMLList using the child() function, I end up with an empty XMLList. The same thing is true for when I try to use this.dropLocationsXML[1], and the valueOf() method.

As you can see I only need to extract the x and y attributes from each of the feature tags. The trace() statement gives the XML output shown ab开发者_C百科ove.

Does anyone know how to access the root nodes of the XML lists, so that I can use the x and y attributes?


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

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜