So I’m trying to get better at AS3, and am working on a file that uses XML. I’ve got some of it to work, but can’t wrap my head around this. My XML looks kinda like this:
<portfolio>
<piece>
<image>portfolio/01.jpg</image>
<description>one</description>
<link>http://somelink.com/</link>
</piece>
</portfolio>
with more than one “piece” obviously.
I can get the XML and do stuff with the images (put them all on the stage with a for loop). Next I want to make the images link to the URLs, but I can’t figure out how to assign the corresponding variable to the movieclips.
I load the XML and run my for loop:
function xmlLoaded(e:Event):void {
var loadedxml:XML = new XML(e.target.data);
for (var i:uint=0; i<loadedxml.piece.length(); i++)
{
var pieceholder:MovieClip = new MovieClip();
portfolio.addChild(pieceholder);
pieceholder.buttonMode = true;
// how to get just the URL we need?
**linky = loadedxml.piece.link.text()*;**
var pieceloader = new Loader();
var pictURLReq:URLRequest = new URLRequest(loadedxml.piece.image.text()*);
pieceholder.addChild(pieceloader);
pieceloader.load(pictURLReq);
pieceloader.addEventListener(MouseEvent.MOUSE_DOWN, linkygo);
}
}
and have a function for the link click:
function linkygo(e:MouseEvent):void
{
var strURL:URLRequest = new URLRequest(linky);
navigateToURL(strURL, "_blank");
}
and what happens? all the buttons go to the same link, the last one from my XML.
how can I make the buttons go to the correct, corresponding URL?
Thanks!!!