Pagination using arrays: Can someone help?

I’ve been trying to figure out how to return iterative arrays from a loop for pagination. Can someone please help me accomplish this and clean up my code?

As the code stands below, I need to clean-up the remaining mc’s. I plan on doing this by comparing the outputted slice arrays to the main one, and pass any keys not mentioned into to their own iterated array.

I think I’m close, but I can’t get over this last hurdle alone. Help would be greatly appreciated!

Thanks


var totalImg:Array = new Array();
var howManyImgs:Number = 66;
var totImgTally:Number = null;
var count:Number = 0;
var lastCount:Number = null;
var imgPerPage:Number = 8;
for (var i:Number = 0; i < howManyImgs; i++) {
    totalImg.push(this.createEmptyMovieClip("imgHolder_" + i, this.getNextHighestDepth()));
}
totImgTally = totalImg.length;
for (var j:Number = 0; j < totImgTally; j++) {
    if (count <= 0) {
        firstCount = count;
        trace("firstCount" + firstCount);
    }
    count++;
    trace("loop" + count);
    if ((count % imgPerPage) == 0) {
        //trace(totalImg / imgPerPage);
        lastCount = count;
        firstCount = Number(lastCount - imgPerPage);
        trace("lastCount:	" + lastCount);

//I'd like to return iterated arrays containing the appropriate mc's, but I don't know how. If
//I put a return statement in, this loop quits, but I don't know why.

        var tempLoopArray:Array = totalImg.slice(firstCount, lastCount);
        trace("tempLoopArray" + tempLoopArray);
    }
// As it stands, I need to clean-up the remaining mc's. I plan on comparing the sliced
//arrays to the main one, and pass the remaining keys to their own iterated array.
}

I was able to find a solution after a few days hacking it up. I’d like to know ways of making this more efficient, though…