[AS2] - Problem with code not returning an array

Right now, i have this code that’s supposed to return the an array that holds the values that were contained within an XML node.


function gatherXmlData():Array    {
  var calendarData:XML = new XML();
  var currentCalendarData:Array = new Array();
  var dateInfo_array:Array = new Array();
  var inc:Number = new Number(0);
          
  calendarData.load("http://localhost/curves/calendar/admin/calendar.xml");
  calendarData.ignoreWhite = true;
  calendarData.onLoad = function (loaded:Boolean)    {    
     if (calendarData.loaded)    {
        currentCalendarData = calendarData.firstChild.childNodes;
        for (inc = 0; inc < currentCalendarData.length; inc++)    {
          dateInfo_array[inc] = currentCalendarData[inc].firstChild.firstChild.nodeValue.split("-", 3);
        }
     }
  }
  return dateInfo_array;
}

for some reason, the code won’t return anything. the output just says “undefined”. Would a good workaround consist of putting the return function within a setInterval method?