2010-01-11 29 views
0

我試過很多不同的方式來訪問屬性的名稱,但只是無法讓它工作。AS3 XML,具有屬性的nodeName出現空白

當前功能:

protected function applyProperties(_axml:XML):void 
{ 
    var list:XMLList = _axml.properties; 
    var list2:XMLList = list.attributes(); 

    for (var i = 0; i < list2.length(); i++) { 
     trace(list2[i].nodeName.toString()); 
    } 
} 

它引用的XML:

<content type="media"> 
<target>warning.png</target> 
<properties x="20" mouseEnabled="$false"></properties> 
</content> 

我都試過了名字,我試圖尋找它作爲一個對象,就找上計算器的解決方案..到目前爲止,沒有任何工作爲我工作。最初我有這樣的屬性節點: 擔心閃存解釋不正確。

編輯:這似乎是XML被interpretted而不是打印出來..

回答

1

list2中[I]是一個XML對象。

XML對象沒有nodeName,這是一個XMLNode對象。

嘗試

list2[i].name().toString(); 
0

我需要這個我的一個項目,這段代碼工作作爲一個魅力:

for (var u:uint=0; u<myXMLList[i].attributes().length(); u++){ 
       LevelOne::DataXML.questionset..q[i][email protected][myXMLList[i].attributes()[u].name().toString()] = myXMLList[i].attributes()[u]; 
       LevelTwo::DataXML.questionset..q[i][email protected][myXMLList[i].attributes()[u].name().toString()] = myXMLList[i].attributes()[u]; 
       LevelThree::DataXML.questionset..q[i][email protected][myXMLList[i].attributes()[u].name().toString()] = myXMLList[i].attributes()[u]; 
      } 

感謝WORMSS!