Dynamic naming with addChild() - I still don't get it

Hi everyone. New to the boards here, stumbled upon them via some excellent tutorials on the site.

I’ve been working on a little program, basically a shell to allow miniature wargames (among other things) to be played via a play-by-email/messageboard. Basically, you have an XML file that stores your pieces (be they the black chess pieces, a deck of cards or a 1,500 point orcish army), another which stores all the pieces in play (a snapshot of how things look), and then the flash app which takes the second XML’s data and puts everything down.

Anyway, this is the point where I hit a snag. I have what amounts to an army/deck builder, where you assemble the first XML. When you open an existing XML, it goes through, gets the name attribute (<unit name=“whatever”>), and makes a list of all of them, with an edit button beside each. Obviously, this is a for… each… in loop, for each unit in the xml file.

My problem is, I then need to refer to a specific one afterwards - when you hit the second Edit button, it needs to show the details for unit[1], when you hit the fourth, it shows unit [3]. I’ve searched this site, and gotten the following:

for each (i in input.category.unit) {
    bUnit = new Button();
    bUnit.x = 150;
    bUnit.y = 185 + (25 * j);
    bUnit.width = 25;
    var unitIndex:String = String(bUnit.name.split("instance")[1]);
    bUnit.name = "bUnit" + j;
    bUnit.label = "";
    bUnit.addEventListener(MouseEvent.CLICK,editUnit);
}

This works, it makes the right number and whatever, but I can’t figure out how to reference them afterwards. j just becomes whatever it was last used, so I can’t go (“bUnit”+j), and I must be missing something with the getChildByName that was recommended in other threads.

Can anyone help a slow-witted lad? The rest of the project’s coming along nicely, until I hit this and everything stopped. Perhaps if you speak slowly, and avoid big words it’ll sink in a little easier.

Cheers,

tic