Recursive functions and loops

Hi guys, I’m having a problem here.

I’m trying to create a minesweeper game as exercise, but I stumbled upon a problem.

I’ve cleaned the code for you so only the relevant code is here:


function expand(cell) {
        getbounds(bounds,cell.row,cell.col);
        var sum:Number = 0;
        for (i = bounds[0]; i <= bounds[1]; i++) {
            for (j = bounds[2]; j <= bounds[3]; j++) {
                var cellName:String = "cell"+i+"x"+j;
                    if (_root[cellName].bomb) {
                        sum++;
                    }
            }
        }
        cell.txt = sum;
        
        if (sum == 0) {
            for (i = bounds[0]; i <= bounds[1]; i++) {
                for (j = bounds[2]; j <= bounds[3]; j++) {
                                        
                    cellName = "cell"+i+"x"+j;
                    trace (cellName);
                    if (_root[cellName].txt == " ") {
                        trace ("1");
                        expand(_root[cellName]);
                        trace ("2");
                    }
                }
            }
        }
   
}
var bounds = new Array(4);

function getbounds(bounds, row, col) {
    bounds[0] = Math.max(1, row-1);                // Minimale hoogte dat hij moet checken
    bounds[1] = Math.min(rows, row+1);            // Maximale hoogte dat hij moet checken
    bounds[2] = Math.max(1, col-1);                // Minimale breedte dat hij moet checken
    bounds[3] = Math.min(columns, col+1);        // Maximale breedte dat hij moet checken
}



the getbounds function delivers me the direct neighbors. 8 of them to be exactly. Or, to say it better, it gaves me the maximum values of each.

The 2 loops go trough these values, and check each of the value of 1 neighbor. It works great. But if I hit a square that isn’t connected with a bomb, I want to do this function on each neighbor. So I use the recursive function method. I just simply recall it. So the first neighbor that’s in line for the expand() function is topleft. And it works also great on that. But instead of cleaning the loop it will take the topleft neighbor of the next one as well.

Since flash works per line based on his code, I understand why he is doing that. But I do not understand is why flash breaks the loop.

Here is a picture for a better view:

Does anyone know how to solve this?