Hi people,
I’m having some trouble trying to use the xml’s array to store into the main fla file’s array so that i can randomize the array for use. Any idea how I could extract the data out from the xmlloader?
Here is the code for the main fla file:
Code:
var xmlLoader: URLLoader = new URLLoader();
var xmlData: XML = new XML();
var factsArrays: Array = new Array();
function xmlTutorial()
{
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("FactText.xml"));
}
function LoadXML(e:Event):void
{
trace("XML File Loaded");
xmlData = new XML(e.target.data);
for (var i in xmlData.item) {
factsArrays.push({text:xmlData.item*.text, url:xmlData.item*.url});
}
trace(factsArrays[0].text);
trace(factsArrays[1].text);
}
var newFactArray:Array = new Array();
function startGame():void{//we'll run this function every time a new level begins
for(var i:int=0;i<enemyArray[currentLvl-1].length;i++){
if(enemyArray[currentLvl-1]* != 0){
enemiesLeft ++;
}
}
this.xmlTutorial();
factRandomArray();
trace(newFactArray[0].toString());
trace(newFactArray[1].toString());
trace(newFactArray[2].toString());
trace(newFactArray[3].toString());
trace(newFactArray[4].toString());
}
//randomize the facts
function factRandomArray():Array {
while(factArray.length > 0)
{
var obj:Array = factArray.splice(Math.floor(Math.random()*factArray.length), 1);
newFactArray.push(obj[0]);
}
return newFactArray;
}
Thanks in advance