# Assign numbers to each XML item

**URL:** <https://forum.kirupa.com/t/assign-numbers-to-each-xml-item/149626>\
**Category:** flash\
**Created:** [May 31, 2005, 4:48am UTC](https://forum.kirupa.com/t/assign-numbers-to-each-xml-item/149626 "2005-05-31T04:48:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgfl](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hgfl](https://forum.kirupa.com/u/hgfl)\
**Post date:** [May 31, 2005, 4:48am UTC](https://forum.kirupa.com/t/assign-numbers-to-each-xml-item/149626/1 "2005-05-31T04:48:33Z")

</div>

This is kind of hard to explain…

I’ve got an XML document that contains names and images for an image gallery, with a menu on the main page, allowing people to click the menu item to display the corresponding image and name.

[AS]  
for (i=0; i\<total; i++) {  
thename\* = items\*.childNodes[0].firstChild.nodeValue;  
image\* = items\*.childNodes[1].firstChild.nodeValue;

var myItem = item\_mc.main\_btn;  
item\_mc.menuitem\_txt.text = thename\*;//place text on menu items  
myItem.onRelease = displayCharacter;//goes to function which passes variable according to content  
myItem.startPoint = i;//tells previous/next buttons where in the XML document we started so it knows which characters come before and after  
}  
[/AS]

I need to be able to assign each of these items a number. This COULD be done by adding a line to the XML doc with a number, then adding an extra line to the ActionScript like this: number\* = items\*.childNodes[2].firstChild.NodeValue;

The trouble is, it is intended that the XML document will be updated regularly, with new items being added in-between exisiting items, therefore, if I had item number 1, followed by item number 2, then wanted to add an extra item after 1, I’d have to call it 2, then rename the existing 2 to 3, and so on.

What I need to do is somehow dynamically give each item a number in Flash as the XML is loaded so number\* = ???  
(it needs to be number\* because \* is used later to refer to items)  
Can anyone help with telling me how to dynamically give each item a number in this way?? Thanx
