I am pulling a url from an attribute in the xml, but it writes over the variable in the for loop and I can’t figure out how to assign the link to the buttons in the for loop. interactiveContainer.viewProject is the button I want to open a link in a new window. url is the variable that I’m storing the projURL attribute from the xml too. I can load the attribute allright and I can trace the attributes from the xml. but when I try to assign the url to the buttons it only opens the last url in the xml and writes over the rest. this snippet of code is just a constructor and a couple of methods from the class, but essentially what I’m asking is how do you duplicate a button in a for loop and assign a specific url attribute to each button?
public function InteractiveContent() {
xmlLoader=new URLLoader ;
xmlLoader.load(new URLRequest("xml/Portfolio.xml"));
xmlLoader.addEventListener(Event.COMPLETE,loadXML);
}
private function loadXML(e:Event):void {
xmlLoader=new URLLoader ;
xmlLoader.load(new URLRequest("xml/Portfolio.xml"));
xmlLoader.addEventListener(Event.COMPLETE,loadXML);
function loadXML(e:Event):void {
xml=XML(e.target.data);
xmlList=xml.children();
//trace(xmlList.length());
for (var i:int; i < xmlList.length(); i++) {
imageURL=xmlList*.@imgSrc;
title=xmlList*.@title;
url=xmlList*.@projURL.toString();
date=xmlList*.@date;
imageLoader=new Loader ;
imageLoader.load(new URLRequest(imageURL));
interactiveContainer=new InterActiveContainer;
interactiveContainer.y=450 * i + 190;
imageLoader.y=50;
interactiveContainer.projectName.text=title;
interactiveContainer.dateTime.text=date;
addChild(interactiveContainer);
interactiveContainer.addChild(imageLoader);
interactiveContainer.viewProject.addEventListener(MouseEvent.CLICK,callLink);
}
}
}
}
private function callLink(e:MouseEvent):void {
var request:URLRequest=new URLRequest(url);
try {
navigateToURL(request,"_blank");
} catch (e:Error) {
trace("Error occurred!");
}
}