Hiya Guys,
I have a script that that loads an XML file (filled with image paths and urls) and navigates the xml object until it reaches all the nodes I wish to grab. Then, it saves the image paths to an array and the same for the urls.
What I need to do is for every imagepath/url combination, I wish to create a button. When you click this button it triggers the URL in a new window, but also displays the image relating to the image path on the flash stage.
I know how to create buttons, and instances of buttons. I am not sure how to pass the values to the button and create a button for every imagepath/url pair and display the image/trigger the URL.
Could someone help?
P.S. The last couple of actionscript lines are probably redundant. I was just experimenting alittle but I fear I have hit a brick wall with this.
XML file
Code:
<root>
<image>
<path>image1.gif</path>
<url>http://www.google.co.uk/</url>
</image>
<image>
<path>image2.gif</path>
<url>http://www.yahoo.co.uk/</url>
</image>
<image>
<path>image3.gif</path>
<url>http://www.hotmail.co.uk/</url>
</image>
</root>
Actionscript code:
Code:
//Create new instance of XML for Flash to parse
var my_xml = new XML();
//Remove shitespace from xml file
my_xml.ignoreWhite = true;
//Load XML
my_xml.onLoad = function(success){
//If xml loaded
if (success){
CreateMenu(this);
}
}
//This function navigates the xml actionscript object
function CreateMenu(menu_xml){
//Target the nodes you need and save them to the variable items
var items = menu_xml.firstChild.childNodes;
//Loop through each node
for (var i=0; i<items.length; i++) {
//Target the values of each node and resave to a new variable
var imagepath = items[i].firstChild;
var imagepath_nodeValue = imagepath.firstChild;
var url = items[i].childNodes[1];
var url_nodeValue = url.firstChild;
trace(imagepath_nodeValue);
trace(url_nodeValue);