XML and dynamically creating buttons

First of all, I’m sorry if this has been answered in part or in whole elsewhere - I’ve been looking and I can’t find anything directly related.

So I have this loop generating buttons based upon how many entries there are in my XML:

for (j=0; j < base.image.length(); j++) { 
        trace(j);
        var newButton:imgButton = new imgButton();
        newButton.x  = 545+(j*25);
        newButton.y = 200;
        var butName = "button" +j;
        newButton.name = butName;
        this.addChild(newButton);
        }

Now I’m just wondering what the best way of assigning control to the buttons is (i.e. making them do something,). I’m wanting each created button to load a different image (defined in the xml) if that’s of any use.

Do I need to add event listeners dynamically or something? :S

Sorry for my idiocy, I’ve never had to do anything like this before :smiley:

My genuine thanks for your time,

samm