flash actionscript:
Hello, all! I'm trying to parse an XML file into a collection of generic
Objects that maintain the same heirarchy that exists in the original XML. And I
can't. :-(
I can create Objects based on the desired nodes, but I can't seem to create an
Object as a property of a previously-created Object; hence, I lose the
heirarchy.
Here's my XML: (Code at the bottom)
And here's what little bit of script I have left: (Frustration! kills
Actionscript dead!) (Code at the bottom, too!)
Obviously, the generateObjects() function just creates a bunch of unrelated
Objects. What I'd like to get is something like this:
navtexts = {};
navtexts.course_map = "Course Map";
navtexts.help = "Help";
.
.
.
parts = {};
parts.section_1 = {};
parts.section_1.title = "Section 1";
parts.section_1.topic_1 = {};
parts.section_1.topic_1.title = "S1 Topic 1";
parts.section_1.topic_1.text_1 = "Text one goes here.";
And so on and so forth...I would greatly appreciate any suggestions!!! Thanks
in advance!
[XML --]
<bizmod>
<navtexts>
<course_map title="Course Map" />
<help title="Help" />
<captions_off title="Turn captions on" />
<captions_on title="Turn captions off" />
<topic title="Topic" />
<slide_of_1 title="Slide" />
<slide_of_2 title="of" />
<previous title="Previous" />
<next title="Next" />
<exit title="Exit" />
</navtexts>
<parts>
<section_1 title="Section 1">
<topic_1 title="S1 Topic 1">
<slide_1 title="S1 T1 Slide 1">
<text_1>
Text one goes here.
</text_1>
<bullets_1>
<bullet_1 text="Bullet 1 text" />
<bullet_2 text="Bullet 2 text" />
<bullet_3 text="Bullet 3 text" />
</bullets_1>
<text_2>
Text two goes here.
</text_2>
</slide_1>
</topic_1>
</section_1>
</parts>
</bizmod>
[AS --]
bizmodsXML = new XML();
bizmodsXML.ignoreWhite = true;
bizmodsXML.onLoad = function( success ) {
if( success ) {
// Since I don't actually want to make an object out of the root,
// I just pass its firstChild and go from there.
generateObjects( this.firstChild );
} else {
trace('Something has gone horribly wrong.');
}
}
bizmodsXML.load('bizmods_texts.xml');
_global.generateObjects = function( ob ) {
if( !ob ) ob = bizmodsXML;
for( var i = 0; i < ob.childNodes.length; i++ ) {
var tempNode = ob.childNodes[i];
if( tempNode.hasChildNodes ) {
generateObjects( tempNode );
}
}
}