PDA

View Full Version : Maybe I don't know as well as I should.


frankenscarf
03-07-2006, 07:44 AM
Hi again everyone! Hope you're doing well.
So... assuming that I've loaded all my XML properly (and you may indeed assume that) here's the idea:

function chewXML(stuffnjunk) {
for (var i = 0; i<stuffnjunk.firstChild.childNodes.length; i++) {
_root.thingy[i].this = stuffnjunk.firstChild.childNodes[i].attributes.siht;
_root.thingy[i].that = stuffnjunk.firstChild.childNodes[i].attributes.taht;
_root.thingy[i].theOther = stuffnjunk.firstChild.childNodes[i].attributes.rehtoEht;
}
}

Only, I discovered that it doesn't like "_root.thingy[i].this"
It doesn't like the [i] at all and I just don't know how else to target a bunch of thingys onstage.
Now, while I've had success building XML apps and stuff in the past, don't assume I know as much as I probably should. I only just used my 1st array the other week 'cause I'd had no need prior. Just FYI as per my abilities. ;)

Any help greatly appreciated.

astgtciv
03-07-2006, 08:02 AM
"this" is a reserved word, don't use it as a variable name.

frankenscarf
03-07-2006, 12:28 PM
attributes and variables in that code are just there to fill space. the principle of the script remains the same.

Cota
03-07-2006, 01:19 PM
In theory it should work fine....what code are you actually using..?

frankenscarf
03-07-2006, 02:10 PM
function chewXML(elements) {
for (var i = 0; i<elements.firstChild.childNodes.length; i++) {
_root.lmnt[i].eName = elements.firstChild.childNodes[i].attributes.ename;
_root.lmnt[i].eNum = elements.firstChild.childNodes[i].attributes.number;
_root.lmnt[i].eSymbol = elements.firstChild.childNodes[i].attributes.symbol;
_root.lmnt[i].eWeight = elements.firstChild.childNodes[i].attributes.weight;
}
}

lmnt[i] is meant to be an mc named lmnt0, lmnt1, lmnt2, etc. that's already onscreen.

I suppose I could determine the x,y coords needed to set up a periodic table, put them in a giant array and then duplicate the lmnt mc accordingly, but where's the fun in that? Plus, I just want to know why I can't use _root.lmnt[i].eNum

Again, help appreciated.

llapgoch
03-07-2006, 02:58 PM
try

eval(_root.lmnt[i]).eName

newblack
03-07-2006, 03:11 PM
eval is deprecated, try this:

function chewXML(elements) {
for (var i = 0; i<elements.firstChild.childNodes.length; i++) {
var att = elements.firstChild.childNodes[i].attributes;
_root["lmnt"+i] = {ename: att.ename, eNum: att.number, eSymbol: att.symbol, eWeight: att.weight};
}
}

Cota
03-07-2006, 05:52 PM
when doing it this way _root.lmnt[i].eWeight Flash kind of see's it as an array..then it see's .eWeight and doesnt like it.

_root.lmnt[i].eWeight

should be

_root["lmnt" + i].eWeight which Flash will read as a correct path.

frankenscarf
03-08-2006, 05:58 PM
I ended up just tossing an onLoad onto each mc. Works fine. I never did get it to work the other way. I, of course, just now noticed where I might've had a little mistake, so I'll be sure to try it again elsewhere. Thx for the help gang.