views:

302

answers:

1

Hello, I'mm using flex builder 3. I have an xml file that looks like this, notice the flag property. It can be either 0 or 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>

I'm creating an xmllist containing all , and I wanted to each time select a random node only if the flag equals 0. Meaning I have a condition, and according to that select a random node that fits that condition. here's where I try to fit it all:

  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;

any ideas on how I can pick a random node that fits the condition? Thank you!

A: 

Try this:

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());
Robert Bak