PDA

View Full Version : Newbie xml and flash - please help - will be easy for most of you :-)


bexlhoward1
08-14-2006, 04:45 PM
HI, I am trying to learn xml in flash myself and am finding it v.hard!

All i am trying to do is create a little 'story' with 3 pages.I have content loading into flash but I am unable to get the next 'sibling' into an array e.g. the title. I can only get page1's title in the array but I can never get to page 2.

Here is my xml:

<maincontent>
<page1>
<title>Who is he</title>
<story>Duh a monkey that lives in the jungle, thats why they call him the JUNGLE MONKEY</story>
</page1>

<page2>
<title>What does he do?</title>
<story>Swings around from tree to tree singing do wa di di .. di di dum di di do...</story>
</page2>

<page3>
<title>What is he like?</title>
<story>Well you know - just a monkey doing his monkey business!</story>
</page3>

</maincontent>

and here is my actionscript:

//load in the xml file
tut = new XML();
tut.ignoreWhite = true;
tut.onLoad = function(success) {
if (success) {
processstory(tut);
}
};
tut.load("tut.xml");
function processstory(xmlDoc_xml) {

titlearray = new Array();
// xmlDoc_xml is now a reference to the XML
// object where our information is stored


for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) {



trace(n);


if (xmlDoc_xml.firstChild.firstChild.childNodes[n].nodeName == "title") {
trace('The title is'+' '+xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
titlearray.push(xmlDoc_xml.firstChild.firstChild.c hildNodes[n].firstChild.nodeValue);
}

trace(titlearray);
}


}

This only traces the first title, how can i get to the second and the third so i can then display them in my text box????

Any help/guidance or pointing to the right place is thankfully received!

Thanks

Bex