Hello once again Kirupa Community.
Here’s my code:
// Set the position and nodecount variable here
var position = 50;
var nodecount = 4;
// create xml object and load file
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("http://www.url.com/portfolioupdates.php");
// When the xml has loaded...
myXML.onLoad = function(success)
{
// make sure there is data there
if(success)
{
// Get the root element
var nodes = this.firstChild.childNodes;
// Loop thru the xml
for(i=0; i<9; i++)
{
// Duplicate as many clips needed by the xml and
// position them on top of each other
nameMC.duplicateMovieClip("nameMC"+i, i, {_x:190, _y:position});
// Create a holder clip which will hold a reference to
// each duplicate instance. This is a shortcut method that
// makes using properties/methods easier to manipulate
var clip:MovieClip = _root.all.contentMain["nameMC"+i];
// Store the clientname
var clientname = this.firstChild.childNodes[nodecount-4].firstChild.nodeValue;
var des = this.firstChild.childNodes[(nodecount-3)].firstChild.nodeValue;
var urlvar = this.firstChild.childNodes[(nodecount-1)].firstChild.nodeValue;
var datevar= this.firstChild.childNodes[(nodecount-2)].firstChild.nodeValue;
var siteurl = this.firstChild.childNodes[(nodecount-1)].attributes.siteurl;
trace (siteurl);
// Assign it to the textfield
clip.nametxt.text = clientname;
clip.datetxt.text = datevar;
clip.destxt.text = des;
clip.urltxt.text = urlvar;
clip.testtxt.text = siteurl;
clip.test2txt.text = siteurl;
[COLOR="Red"]clip.urlbtn.onRelease = function() {
getURL (siteurl, "_blank");
}[/COLOR]
// Space each duplicate along the y axis
position = position + 200;
var nodecount = nodecount + 4;
}
} else {
// If no data, report an error
trace("Could not load xml file");
}
}
Everything is working except the red code. The URL is working, however, the URL it points to is always the last node attribute even if the link is in any other cycle of the loop.
When I trace(siteurl) I get an output that lists the URL’s that I want in correct order, like this:
http://www.url1.com
http://www.url2.com
http://www.url3.com
http://www.url4.com
http://www.url5.com
But the problem is, whenever i click on the urlbtn within that new duplicated clip, it is always pointing to the last URL listed by the output. Any idea why? The urlbtn should be pointing to the corresponding url that is defined by the number of times the loop has occured. So, if the loop has gone through twice, the urlbtn should point to http://www.url2.com, but it’s not, it’s pointing to the last URL. Hopefully this makes sense.
Any suggestions here? Thanks guys.