PDA

View Full Version : actionscript/xml problem



x.vector
October 4th, 2003, 08:10 AM
hej peeps ..

after reading the tuts here on kirupa and as.org i started
fiddling around myself with this xml-shiznit ...

i used LostinBeta's/Senocular's xmlmenu.zip as reference ...

i created 3 buttons that will link to 3 different sites
the buttons get their info from xml file ...

when i run my file the buttons appear, each with the
correct <ITEM NAME/> only they all link to the same site ..
(the last "<ITEM URL/>" entry in the xml file)

how come .. ??

i doubledouble checked the whole thingie ,searched the forums,
read the tuts again ... but i can't figure out why they all link to the same site ..

here's my xml :

<?xml version="1.0"?>
<LINKS>
<ITEM NAME="check this site" URL="http://www.google.nl/" TARGET="_blank" />
<ITEM NAME="kirupa.com" URL="http://www.kirupa.com/" TARGET="_blank" />
<ITEM NAME="actionscript.org" URL="http://www.actionscript.org/" TARGET="_blank" />
</LINKS>
and here's the actionscript i use

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function (success) {
myITEM = this.firstChild.childNodes;
if (success) {
for (i=0; i<myITEM.length; i++) {
myATTRIBUTES = myITEM[i].attributes;
myButton = _root.attachMovie("textClip", "textClip"+i, i);
myButton._x = myButton._y = 100;
myButton._y += 40*i;
myButton.buttonLabel.autoSize = true;
myButton.buttonLabel.text = myATTRIBUTES.NAME;
myURL = myATTRIBUTES.URL;
myTARGET = myATTRIBUTES.TARGET;
myButton.onRelease = function () {
getURL(myURL, myTARGET);
}
}
}
}
myXML.load("links.xml");

kode
October 4th, 2003, 08:57 AM
myButton.myURL = myATTRIBUTES.URL;
myButton.myTARGET = myATTRIBUTES.TARGET;
myButton.onRelease = function () {
getURL(this.myURL, this.myTARGET);
};
??

x.vector
October 4th, 2003, 11:10 AM
hej thnx for the fast reply dude ..

it works like a dream ...

could you mebbe explain why it works this way .. ?

thnx enniewee

kode
October 4th, 2003, 11:26 AM
Because after the loop is finished, the value of myATTRIBUTES.URL and myATTRIBUTES.TARGET will always (unless you change it again, of course) be the same; which is the value of the attributes of the last node. You need to store the value of the attributes in a variable in the movie clip. Am I making any sense? :P

x.vector
October 4th, 2003, 11:28 AM
yes you do .. i understand ...

thnx again

kode
October 4th, 2003, 11:29 AM
Ok! You're welcome. :beam: