I am attempting to read an XML file and add all the elements to a ComboBox in a random order (I have no idea how to do this). I have produced a ComboBox on stage called Primary_CB. I have my XML all set in the following format...
<data>
<elements>
<element1>
<primary>Male Character</primary>
</element1>
<element1>
<primary>Female Character</primary>
</element1>
</elements>
</data>
My AS3 basically reads the XML file and populates the contents into the ComboBox like so...
Primary_CB.prompt = "Items";
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var xmlAry:Array = new Array();
var xmlURL:Array = new Array();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("IdeaElements.xml"));
function LoadXML(e:Event):void
{
xmlData = new XML(e.target.data);
trace(xmlData..primary.length());
for (var i:uint=0; i<xmlData..primary.length(); i++)
{
xmlAry.push(xmlData..primary[i]);
xmlURL.push(xmlData..url[i]);
Primary_CB.addItem( { label: xmlAry[i], data:i } );
Primary_CB.addEventListener(Event.CHANGE, action);
}
}
function action(e:Event):void
{
var no:Number = Number(Primary_CB.selectedItem.data);
trace(xmlURL[no]);
}
How would I make it randomize the order of the elements and also add the first element in the list to the prompt of the ComboBox?