Why is my array length 0

I am push iems int the array but outside the functio it s zero, the declaration is of global scope. thanks for any help
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var imagelist:XMLList=new XMLList();
var imageArray=[];
var numberofItems:Number;

xmlLoader.load(new URLRequest(“http://localhost/flash/loadXML.xml"+"?uniq=” + new Date().getTime()));

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
function LoadXML(e:Event):void {
//XML.ignoreWhitespace = true;
xmlData = new XML(e.target.data);
parseImg(xmlData);

}
function parseImg(imgxml:XML):void{
imagelist=imgxml.data.productdata.pid

for each (var  item:String in imagelist){ 
imageArray.push(item)


}

}
trace(imageArray.length)