Add loop items to array

This is a little hard to explain…
What I’ve got is a menu that loads images as buttons. It will only display menu items that are within a certain group (i.e. if themenuitem.nodeValue == groupid[q] then it will display that menu item.

Each of the menu items has a unique number (Itemnumber[n]). I have a loop that goes through and displays the menu items that are within a certain group. I am currently able to also find out the unique number of each of the menu items where themenuitem.nodeValue == groupid[q], but what I want to do with these numbers, is place them all into an array as it loops through…

So, say for example, it finds an item in the loop. It tells me this item is number 4 (if I tell it to trace(Itemnumber[n]) within the loop). Then, it finds another item in the loop, and it tells me this item number is 6. I want to be able to add items to an array as it loops through, so I’ll have an array at the end like this: (4, 6).

Currently my ActionScript looks like the following. Never mind if there are variables that are not defined in there – they have been defined in other parts of my movie.

function displayGroupMenu() {
for (n=0; n<total; n++) {
myGroups = Items[n].childNodes[11];
numOfGroups = myGroups.childNodes.length;
for (k=0; k<numOfGroups; k++) {
themenuitem = myGroups.childNodes[k].firstChild;
////////
thenum = Itemnumber[n];
numarray = [thenum];
numarraylength = numarray.length;
////////
if (themenuitem.nodeValue == groupid[q]) {
///////
numarray[numarraylength] = n;
//what I want to happen here is that, as the loop occurs,
//if themenuitem.nodeValue == groupid[q], then add the number (thenum)
//to the array, so in the end, I'll have an array of unique numbers that
//correspond to the items that the groupid[q] was successfully found in
trace("numbers array: "+numarray);
trace("numbers of items in array: "+numarray.length);
////////
var theitem_thumb_spacing = 31;
var theitem_columns = 3;
var currenttheitemPicture = groupmenuimage[n];
var currenttheitemThumb_mc = mc_group_Items.createEmptyMovieClip("radicals_mc"+n, n);
currenttheitemThumb_mc._x = (n%theitem_columns)*theitem_thumb_spacing;
currenttheitemThumb_mc._y = Math.floor(n/theitem_columns)*theitem_thumb_spacing;
currenttheitemThumb_mc.createEmptyMovieClip("theitem_thumb_container", 0);
currenttheitemThumb_mc.theitem_thumb_container.loadMovie(radicalmenuimage[n]);
currenttheitemThumb_mc.onRelease = displayItem;
currenttheitemThumb_mc.theitemStartPoint = n;
}
}
}
}

As you can see, I’ve made an attept at achieving this by trying numarray[numarraylength] = n; – but all this does is send me an array, then overwrite it next time it loops (so I get an array like (4, 4), then one like (6, 6). I’ve added comments in the code to further explain what I’m trying to do. I know it may be a little hard to understand, but I hope there’s some ActionScript pro out there who can understand it and help with this!!

I would very much appreciate that!! Cheers.