如何获取所有XML-Nodes属性值?

时间:2010-02-19 10:26:51

标签: xml flash actionscript-3

这是xml文件

<glossary>
<alphabet id="A">
    <term heading= "Anchor" definition="A mechanical device that prevents a vessel from moving"/>
        <term heading= "Atlas" definition="A collection of maps in book form"/>
    </alphabet>
    <alphabet id="D">
        <term heading= "Delay" definition="Time during which some action is awaited"/>
    </alphabet>
    <alphabet id="R">
        <term heading= "Risk" definition="A source of danger; a possibility of incurring loss or misfortune"/>
        <term heading= "Rotate" definition="Turn on or around an axis or a center"/>
    </alphabet>

</glossary>

fla文件:

import fl.controls.List;
import fl.events.ListEvent;
var xmlLoader:URLLoader= new URLLoader();
xmlLoader.load(new URLRequest("datalist.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
var xmlData:XML= new XML();
var myArr:Array= new Array();
function xmlLoaded(e:Event):void {
    xmlData= new XML(e.target.data);
    xmlData.ignoreWhitespace = true;
    //trace(xmlData.term.length());
    ParseData(xmlData);
}
function ParseData(dispTerm:XML):void {
    var termList:XMLList = dispTerm.alphabet.term.@heading;
    //trace(termList)
    var meaningList:XMLList = dispTerm.alphabet.term.@definition;
    //trace(meaningList)
    for (var i:int = 0; i < termList.length(); i++) {
        var termElement:XML = termList[i];
        var meaningElement:XML = meaningList[i];
        mytermList.addItem({label:termList[i], data:termList[i]});
        mytermList.addEventListener(ListEvent.ITEM_CLICK, itemclicked);
        //meaningList.definition=dispTerm.alphabet.term.@definition;
        //mymeaningList.addItem({label:meaningList[i], data:meaningList[i]});
    }
}

function itemclicked(evt:ListEvent):void {
    //trace(evt.item.definition.attribute);
    /*for (var i:int = 0; i < termList.length(); i++) {
    mymeaningList.addItem({label:meaningList[i], data:meaningList[i]});
    }*/
}

在此示例中,标题显示在列表中,我希望当用户点击listitem时,相关定义将显示另一个列表。 这个文件中有可能吗?或者我必须采取另一个类文件?

1 个答案:

答案 0 :(得分:0)

是的,可以在一个FLA文件中使用。

只是您的termList的事件监听器,以便在翻转时将含义添加到您的meaningList。像这样:

termList.addEventListener(ListEvent.ITEM_ROLL_OVER, showDetails);

function showDetails(e:ListEvent):void {
    //code to add item to meaningList
}