PDA

View Full Version : XML and ActionScript



VersusMG
November 11th, 2005, 10:20 AM
stop();
//
//
path = this;
function loadXML(success) {
if (success) {
xmlNode = this.firstChild.childNodes;
for (i=0; i<xmlNode.length; i++) {
var img = xmlNode[i].childNodes[0].nodeValue;//Math.random();
container.loadMovie(img);
}
}
}
var news_xml = new XML();
news_xml.ignoreWhite = true;
news_xml.onLoad = loadXML;
news_xml.load("headers.xml");

I it to randomly pick one of the childNodes and display it in the container. I tried to place in a Math.random(); but I wasn't sure where to put it.

mathew.er
November 11th, 2005, 10:53 AM
maybe this one?

stop();
//
//
path = this;
function loadXML(success) {
if (success) {
xmlNode = this.firstChild.childNodes;
var img = xmlNode[Math.floor(xmlNode.length*Math.random())].childNodes[0].nodeValue;
container.loadMovie(img);
}
}
var news_xml = new XML();
news_xml.ignoreWhite = true;
news_xml.onLoad = loadXML;
news_xml.load("headers.xml");

VersusMG
November 11th, 2005, 11:02 AM
Thanks! That worked great!

mathew.er
November 11th, 2005, 11:21 AM
I'm glad to help :thumb: