我正在使用flex builder 3。 我有一个看起来像这样的xml文件,请注意flag属性。它可以是0或1:
<question id="2">
<short>OMG</short>
<meaning>Oh My God</meaning>
<hint>OMG did you hear they broke up?!</hint>
<flag>0</flag>
</question>
<question id="3">
<short>BTW</short>
<meaning>By The Way</meaning>
<hint>BTW, there's no class today</hint>
**<flag>0</flag>**
</question>
我正在创建一个包含all的xmllist,并且我希望每次只在标志等于0时选择一个随机节点。意思是我有一个条件,并根据那个选择一个符合该条件的随机节点。这是我试图适应这一切的地方:
var countNodes:int = 25;
var i:int = int(Math.random() * 25);
var xList:XMLList = loadedXML.question[i].short;
quesLabel.text = xList.text();
test2.text=loadedXML.question[i].meaning;
关于如何选择符合条件的随机节点的任何想法? 谢谢!
答案 0 :(得分:1)
试试这个:
var filteredNodes:XMLList = loadedXML.(flag==0);
var countNodes:int = filteredNodes.length()
var i:int = int(Math.random() * countNodes);
var randomNode:XML = filteredNodes[i];
trace (randomNode.toXMLString());