I have a function populateEventDates();
inside this function it calls a function loadEventXML();
this is my XML function:
Code:
loadEventXML = function(month:Number){
var events_xml = new XML();
events_xml.ignoreWhite = true;
events_xml.onLoad = function(success){
if (success) {
for (var i:Number = 1; i <= events_xml.childNodes.length; i++){
var eventDate = events_xml.childNodes[i-1].childNodes[0].firstChild.nodeValue;
var eventName = events_xml.childNodes[i-1].childNodes[1].firstChild.nodeValue;
var eventText = events_xml.childNodes[i-1].childNodes[2].firstChild.nodeValue;
_root.eventData[i*3-3] = eventDate;
_root.eventData[i*3-2] = eventName;
_root.eventData[i*3-1] = eventText;
}
trace("XML Data for " + monthNames[month] + " loaded");
}else{
trace("Error loading XML file for " + monthNames[month]);
}
}
events_xml.load("xml/" + (month+1)+".xml");
}
Later in teh populateDates() fucntion it calls a fuunction that uses the XML data now saved to eventData.
Code:
checkForEvent = function(dateCheck:Number){
trace("Checking For Event");
for (var index:Number = 0; index<=_root.eventData.length; index++){
trace("Looking for event");
if (_root.eventData[index] == dateCheck){
trace("Return Event " + _root.eventData[i+1]);
return _root.eventData[i+1];
}
}
trace("No Event Found");
return "";
}
Even though checkForEvent is loaded after loadEventXML, ,in teh trace window I still get "Looking for event" traced once for every check and at teh end I get "Data for " + monthNames[month] + " loaded". Why is the XML not loaded by now?