PDA

View Full Version : Creating a link button from XML content


mightymouse
04-26-2005, 10:09 AM
Hi,

I am working on a CD ROM interface that draws it's content from an XML document. I have a menu which is created "onLoad" using the XML content, and text boxes on the stage which draw their content from the XML doc according to which button in the menu is clicked. All this works fine.

I would also like to add a link button that is generated from an attribute of a node of the XML document - this is the part I can't get to work.

I have tried to do this using the same code as in the menu. I originally got the menu code off the web, but have changed it alot (learning as I go) and added stuff. I understand everything in the code except the use of _root["item"+a] (I know what "item"+a is, but am confused about the use of _root[]) in the menu script, and consequently I think I may be using _root incorrectly in the link button part that I have added.

The script is below, and it all works except the actual link (the URL displays in the new movie clip as it should, but there is no mouse over action and you can't click on it).

Any help or guidance would really be appreciated - Thanks
C


stop();

menu = new XML();
menu.ignoreWhite = true;
menu.load("menu.xml");
menu.onLoad = function(){

//create an array "items" that contains all the info in the "item" nodes
items = this.firstChild.firstChild.childNodes;
for(a = 0; a<= items.length-1; a++){
//attach a new instance of menuItem
_root.attachMovie( "menuItem", "item"+a, a);
//insert text from the "header" attribute into the button's text field
_root["item"+a].itemText.text = items[a].attributes.header;
//Move the movie clip ACCROSS per execution of the loop and set x value
_root["item"+a]._x = 5;
_root["item"+a]._y = 40 + 20*a;

//create new variables (?) to hold the attributes from the relevant "item" node
_root["item"+a].showHeader = items[a].attributes.header;
_root["item"+a].showLicence = items[a].attributes.licence;
_root["item"+a].showDescription = items[a].attributes.description;
_root["item"+a].showURL = items[a].attributes.link;

//create a link button using information from the "link" attribute
_root["item"+a].onRelease = function(){
_root.attachMovie("itemURL", "buttonLink", a, {_x:350, _y:109});
_root["buttonLink"].URLtxt.text = this.showURL;
_root["buttonlink"].onRelease = function(){
getURL(this.showURL, "_blank");
}
//populate text boxes with information form the relevant node attributes
itemHeader.text = this.showHeader;
itemLicence.text = this.showLicence;
itemDesc.text = this.showDescription;
}
}
}

tg
04-26-2005, 02:00 PM
i see a path problem right away.

_root["buttonLink"].URLtxt.text = this.showURL;// this refers to the timeline of _root["item"+a]... so it is looking for _root["item"+a].showURL
_root["buttonlink"].onRelease = function(){
getURL(this.showURL, "_blank");// this refers to the timeline of _root.buttonlink, so its looking for _root.buttonlink.showURL.
}


make sure you know where the variable showURL resides, then use the appropriate path to the variable.

mightymouse
04-27-2005, 01:18 AM
Thanks heaps tg - I get it now, and have got it sorted.

:)