Probably a dumb question, but I've run out of ways to ask google...
I'm doing a little flash app for vocabulary learning. The vocabulary items are <entry>s in an xml file, children of a given <chapter>. The user loops through the vocab entries, and has the option to see only entries from particular chapter(s) they select. What I need is, for the first vocab entry in every selected chapter, its index with respect to the root (so I can then pull a randomised list of vocab entries from all and only the selected chapters).
An abbreviated version of the xml follows:
The chapter selection is held in my arrChpts[] (array of checkboxes, indexed same as xml chapter indices), so I use a loop to test whether a checkbox was selected, count selected chapters ('nrChapters') and get a total of vocab entries to be included ('nrEntries'):
... and in that for-loop I'd like to store all the entry indices in that chapter but wrt root rather than the chapter. For example, with reference to above xml snippet, if a user selected the chapter "pronouns" but not "numbers", I'd want the index for "pronouns"'s first (and any subsequent) entries - in this case it would be '3' (third <entry> under root).
I've tried so many versions with childIndex and parentNode and whatnot, but none of it makes any sense (and unsurprisingly doesn't work). How do I do this?
The only alternative I can think of would be to store all the xml data of selected chapters in an array, but that seems so.. redundant!
Thanks for your help!
I'm doing a little flash app for vocabulary learning. The vocabulary items are <entry>s in an xml file, children of a given <chapter>. The user loops through the vocab entries, and has the option to see only entries from particular chapter(s) they select. What I need is, for the first vocab entry in every selected chapter, its index with respect to the root (so I can then pull a randomised list of vocab entries from all and only the selected chapters).
An abbreviated version of the xml follows:
Code:
<vocab>
<chapter>
<chaptername>Numbers</chaptername>
<entry>
<tl>wahed</tl>
<en>one</en>
</entry>
<entry>
<tl>ithnaan</tl>
<en>two</en>
</entry>
</chapter>
<chapter>
<chaptername>Pronouns</chaptername>
<entry>
<tl>ana</tl>
<en>I, me</en>
</entry>
</chapter>
</vocab>
The chapter selection is held in my arrChpts[] (array of checkboxes, indexed same as xml chapter indices), so I use a loop to test whether a checkbox was selected, count selected chapters ('nrChapters') and get a total of vocab entries to be included ('nrEntries'):
Code:
totChapters=dataXML.chapter.length();
totEntries=dataXML.chapter.entry.length();
if (arrChpts) {
for (var i:int=0; i<totChapters; i++) {
if (arrChpts[i].selected) {
nrChapters++;
nrEntries += dataXML.chapter[i].entry.length();
}
}
}
... and in that for-loop I'd like to store all the entry indices in that chapter but wrt root rather than the chapter. For example, with reference to above xml snippet, if a user selected the chapter "pronouns" but not "numbers", I'd want the index for "pronouns"'s first (and any subsequent) entries - in this case it would be '3' (third <entry> under root).
I've tried so many versions with childIndex and parentNode and whatnot, but none of it makes any sense (and unsurprisingly doesn't work). How do I do this?
The only alternative I can think of would be to store all the xml data of selected chapters in an array, but that seems so.. redundant!
Thanks for your help!