You've defined the variable url
, but then called a different (undefined) variable weblinkXML.url
in your getURL call.
Try this instead:
weblinkXML.onLoad = function (success)
{
trace("success is "+success);// success should be TRUE
var url = weblinkXML.firstChild.attributes.href;
trace("url = "+url);
banstead.onRelease = function ()
{
trace("button pressed with "+url);
getURL(url);
}
}
To add more buttons, you might try changing your XML file to look more like this:
<?xml version="1.0" encoding="utf-8"?>
<button buttonName="banstead" targ="_self" href="http://www.marca.com"> </button>
<button buttonName="chipstead" targ="_self" href="http://www.yahoo.com"> </button>
<button buttonName="tadworth" targ="_self" href="http://www.google.com"> </button>
Then make a loop which goes through the XML and makes a button for each item it finds:
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function(success) {
trace("success = "+success);
banstead._visible=FALSE;// hide the original button: we're making copies
for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
// make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
var myButton:MovieClip = banstead.duplicateMovieClip(myName, i+1);
// I've assumed your button has a dynamic text field in it named buttonLabel:
myButton.buttonLabel.text=myName;
myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
myButton.href = weblinkXML.childNodes[i].attributes.href;
myButton.onRelease = function() {
getURL(this.href);// note that each button has it's own href variable
};
}
};
I have made some assumptions about how your project is set up... but I've tested it and it seems to work for me
Let me know how you get on (and don't forget to click the big tick mark to accept this answer if it has helped you - thanks).