2010-07-05 71 views
1

我與此刻的XML列表,它看起來像這樣的工作:如何訪問的XMLList節點AS3

<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 + ([email protected])*35; 
     numY = 4 + ([email protected])*35; 
    } 
} 

現在,當我嘗試使用child()函數訪問此XMLList時,我最終得到一個空的XMLList。 當我嘗試使用this.dropLocationsXML [1]和valueOf()方法時,情況也是如此。
正如你所看到的,我只需要從每個特徵標籤中提取x和y屬性。 trace()語句給出了上面顯示的XML輸出。
有誰知道如何訪問XML列表的根節點,以便我可以使用x和y屬性?

回答

3
for each (var x : XML in dropLocationsXML.feature) { 
    trace("xml: "[email protected]); 

} 
+0

啊我明白了。我認爲你的XML是這樣的: maxmc 2010-07-05 12:32:25

+0

這幾乎做了訣竅: 爲每個(var x:dropLocationsXML中的XML){ \t trace(「xml:」+ x。@ x); } – Bartvbl 2010-07-05 12:32:54

+0

aha :) 感謝您的幫助! – Bartvbl 2010-07-05 12:33:20