Hey guys,
I’ve been working with an XML portfolio most recently, as the thread natronp was kind enough to indulge me in shows. I’m working on the same problem but thought it would be a little misleading to add to that thread since my most recent problem isn’t directly related to its title.
I’m loading an external XML file, obviously, and populating arrays with its data. There’s also a variable that holds the total number of projects within the XML file because the menu they’ll eventually inhabit requires the information for later “for loop” traversal. I can’t seem to get globally declared variables to be visible in other code scopes.
Here’s what I’m working with right now:
////////////////////////////
//global array loading...
_global.thumbs = [];
//_global.description = [];
//_global.tempClips = [];
//_global.totalProjects;
////////////////////////////
//XML LOADING
function loadXML(loaded)
{
if (loaded)
{
//according to "content2.xml," this would set the parser at "<projects>".
xmlNode = this.firstChild;
thumbs = [];
description = [];
**_global.totalProjects = xmlNode.childNodes.length; //should be "3"**
//"totalProjects" here would be 3, because there are three <project>'s...
//ACCORDING TO "content2.xml
for (i = 0; i < totalProjects; i++)
{
thumbs* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
//_global.thumbs = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
/*the second array accesser is set to "2" because in my xml file (content2.xml),
the third child of each project is the description, not the second like this guy's.
*/
_global.description* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
}
//tempClips = populateImageArrays(thumbs);
//displayThumbs(thumbs, tempClips);
}
else
{
trace("File not loaded.");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("content2.xml");
//declare an array to hold the thumbnails...
**trace(totalProjects); //displays "undefined"
**
That’s just the most current incarnation. I’ve tried declaring the variables inside the loadXML function and outside, with later references made both omitting and maintaining the “_global” prefix all along the way. Can somebody please give a definitive answer on how these friggin’ things work?
Thanks,
TheRiddler