adoshi
04-15-2003, 09:08 PM
Hello,
I'm still pretty new to the ins and outs of actionscripting, so please bear with me... Hopefully one of you smarties can point me in the right direction... So here it is...
1. within _root, I load an XML file into an XML object with an .onLoad function which is assumed to be prototype-esque.
2. The onLoad function creates a new custom class object that is a container for the parsed XML object data
3. after function runs and parsing is finished, i try to simply loop through data points within container object (multi-dim array)
function BarGraphData () {
// constructor for BarGraphData class
this.Data = new Array();
this.Sites = new Array();
this.Categories = new Array();
//this.convertXMLtoArray ( data );
}
BarGraphData.prototype.convertXMLtoArray = function ( cNode ) {
for ( cN in cNode ) {
if ( cNode[cN].childNodes.length != 1 ) {
// keep looping through the nodes until you find the text
this.convertXMLtoArray ( cNode[cN].childNodes );
} else {
// you've hit gold... store the values to array
if ( cNode[cN].parentNode.nodeName != null ) {
// confirm that first array dimension is declared as Array()
if (( typeof this.Data[cNode[cN].parentNode.nodeName] ) != "object" ) {
this.Data[cNode[cN].parentNode.nodeName] = new Array();
this.Categories.push( cNode[cN].parentNode.nodeName );
}
// confirm second array dimension is declared as Array()
if (( typeof this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName] ) != "object" ) {
this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName] = new Array();
this.Sites.push( cNode[cN].nodeName );
}
// push data to the array obj
this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName][cNode[cN].attributes.id] = cNode[cN].firstChild.nodeValue;
} else {
this[cNode[cN].nodeName] = cNode[cN].firstChild.nodeValue;
}
}
}
}
function loadXMLData (){
GraphData.convertXMLtoArray ( this.childNodes );
}
GraphData = new BarGraphData ();
GraphRawData = new XML ();
GraphRawData.ignoreWhite = true;
GraphRawData.onLoad = loadXMLData;
GraphRawData.load ( "somefile.xml" );
Problem being, the "global" container contains all of the correct data in the Debug - List Variables window in FMX, yet i get nothing when i trace on the _root level... This seemed to obviously point to a Scoping issue, and I have read the documentation on it, fiddled with differnt syntax, but am still in the dark... Anyone know what I'm doing wrong?
using flash mx 6.0 if that matters...
Thanks in advance...
__________________
I'm still pretty new to the ins and outs of actionscripting, so please bear with me... Hopefully one of you smarties can point me in the right direction... So here it is...
1. within _root, I load an XML file into an XML object with an .onLoad function which is assumed to be prototype-esque.
2. The onLoad function creates a new custom class object that is a container for the parsed XML object data
3. after function runs and parsing is finished, i try to simply loop through data points within container object (multi-dim array)
function BarGraphData () {
// constructor for BarGraphData class
this.Data = new Array();
this.Sites = new Array();
this.Categories = new Array();
//this.convertXMLtoArray ( data );
}
BarGraphData.prototype.convertXMLtoArray = function ( cNode ) {
for ( cN in cNode ) {
if ( cNode[cN].childNodes.length != 1 ) {
// keep looping through the nodes until you find the text
this.convertXMLtoArray ( cNode[cN].childNodes );
} else {
// you've hit gold... store the values to array
if ( cNode[cN].parentNode.nodeName != null ) {
// confirm that first array dimension is declared as Array()
if (( typeof this.Data[cNode[cN].parentNode.nodeName] ) != "object" ) {
this.Data[cNode[cN].parentNode.nodeName] = new Array();
this.Categories.push( cNode[cN].parentNode.nodeName );
}
// confirm second array dimension is declared as Array()
if (( typeof this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName] ) != "object" ) {
this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName] = new Array();
this.Sites.push( cNode[cN].nodeName );
}
// push data to the array obj
this.Data[cNode[cN].parentNode.nodeName][cNode[cN].nodeName][cNode[cN].attributes.id] = cNode[cN].firstChild.nodeValue;
} else {
this[cNode[cN].nodeName] = cNode[cN].firstChild.nodeValue;
}
}
}
}
function loadXMLData (){
GraphData.convertXMLtoArray ( this.childNodes );
}
GraphData = new BarGraphData ();
GraphRawData = new XML ();
GraphRawData.ignoreWhite = true;
GraphRawData.onLoad = loadXMLData;
GraphRawData.load ( "somefile.xml" );
Problem being, the "global" container contains all of the correct data in the Debug - List Variables window in FMX, yet i get nothing when i trace on the _root level... This seemed to obviously point to a Scoping issue, and I have read the documentation on it, fiddled with differnt syntax, but am still in the dark... Anyone know what I'm doing wrong?
using flash mx 6.0 if that matters...
Thanks in advance...
__________________