Hi,
I think I’ve run into a newbie problem. I’m trying to load a number of brand logos and link to the brand’s site using information from an xml list. I’m able to get the information from the list fine but when I try to loop through the list and add the images to the stage only the final image remains on the stage. The others get overwritten by the latest one. Obviously I need a new loader to be created each time I loop through but I can’t figure out how to do this. I’ve thought about implementing an array but haven’t had any luck. Here’s my code so far:
var xmlLoader:URLLoader = new URLLoader();
var brandsURL:URLRequest = new URLRequest("brands.xml");
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(brandsURL);
var loaderX:Number = 50;
var brandsXML:XML = new XML();
brandsXML.ignoreWhitespace=true;
var loader:Loader = new Loader();
function xmlLoaded(evt:Event):void {
brandsXML =XML(xmlLoader.data);
for (var brandName:String in brandsXML.brand) {
trace(brandsXML.brand[brandName].@name);
var request:URLRequest= new URLRequest(brandsXML.brand[brandName].image);
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
var link:URLRequest=new URLRequest(brandsXML.brand[brandName].link);
function onClick(evt:MouseEvent):void {
navigateToURL(link);
}
function imageLoaded(evt:Event):void {
addChild(loader);
loader.x=loaderX;
loader.y=50;
loader.width=209;
loader.height=56;
trace("image loaded");
loaderX+=250;
loader.addEventListener(MouseEvent.CLICK, onClick);
}
}
}
Does anyone know what I need to do to add to stop the loader from replacing itself?
Any help would be greatly appreciated.
Thank you.