Sudoku game - need some help

Hi all,

For those who don’t know the puzzle/game: www.sudoku.com
I’ve got the grid & the check working. I’m not trying to create a generator. Just a fixed setup and 1 solution. Just a fun game we repeat a few times a year in our company as a fun contest. But i still have some small problems to fix. Hope some AS master can help me out. This is the code:

var tFormat:TextFormat = new TextFormat();
tFormat.font = "Verdana";
tFormat.color = 0x666666;
tFormat.align = "center";
tFormat.size = 12;
 
//Horizontal distance betweer textfields
var hor:Number = 40;
//Vertical distance betweer textfields
var ver:Number = 40;
//Start X of 1st field
var startX:Number = 10;
//Start Y of 1st field
var startY:Number = 16;
//
var counter:Number = 0;
//Create first Sudoku Setup
var aSetup = [
 [ "", 6 , "", 1 , "", 4 , "", 5 , ""], 
 [ "", "", 8 , 3 , "", 5 , 6 , "", ""], 
 [ 2 , "", "", "", "", "", "", "", 1 ], 
 [ 8 , "", "", 4 , "", 7 , "", "", 6 ], 
 [ "", "", 6 , "", "", "", 3 , "", ""], 
 [ 7 , "", "", 9 , "", 1 , "", "", 4 ], 
 [ 5 , "", "", "", "", "", "", "", 2 ], 
 [ "", "", 7 , 2 , "", 6 , 9 , "", ""], 
 [ "", 4 , "", 5 , "", 8 , "", 7 , ""]
 ];
 
//Build up grid
for (var i = 0; i<9; i++) {
        for (var j = 0; j<9; j++) {
                counter++;
                // We generate textfields
                var tF:TextField = mcContainer.createTextField("tField"+counter, counter, startX+(j*hor), startY+(i*ver), 30, 20);
    tF.setNewTextFormat(tFormat);
                tF.type = "input";
                tF.maxChars = 1;
                tF.restrict = "1-9";
                tF.align = "right";
                tF.text = aSetup*[j];*
*  **if (mcContainer["tField"+i].text != "") {***
***   mcContainer["tField"+i].selectable = false;***
***  }***
***      }***
***}***
 
***// Error listing***
***error0 = "There is still an error in your Sudoku, hurry up, solve it and win that cake!";***
***error1 = "They told me you were the smartest around here and still there is at least one error";***
***error2 = "You did read the rules right? Come on, you can do it!";***
 
***//Random error msg***
***errorMsg = "error"+random(3);***
*//String with all the right numbers in a row to check if the input from the user is right*
*var sSolution:String = ",9,6,3,1,7,4,2,5,8,1,7,8,3,2,5,6,4,9,2,5,4,6,8,9,7,3,1,8,2,1,4,3,7,5,9,6,4,9,6,8,5,2,3,1,7,7,3,5,9,6,1,8,2,4,5,8,9,7,1,3,4,6,2,3,1,7,2,4,6,9,8,5,6,4,2,5,9,8,1,7,3";*
*//Split up the string where "," is used*
 
*var aCheck:Array =  sSolution.split(",");*
 
*trace(aCheck.length);*
 
*//Submit bt - to check if input is right*
*mcSubmit.onRelease = function(){*
 
*//For loop , looping as long as the length of the solution string of numbers*
*for (i = 1; i<aCheck.length; i++){*
*trace("Current no = " + i);*
*trace("Field = " + mcContainer["tField"+i].text);*
*  trace("Check = " + aCheck*);*
 
*//If looped 82 times the input didn't contain any errors - puzzle solved! :)*
*if (i == 82){*
* trace("Done!");*
* break;*
*}*
 
*//Check every field if input is right, if not, stop the for loop and give error msg*
*  if (mcContainer["tField"+i].text != aCheck*){*
* trace("error");*
*   ***error = errorMsg;***
   break;
  } 
 }
}

Problem 1: What i want to do is to make the given numbers on the grid (see aSetup) to be marked (like bold or something) and non-selectable. See the bold code to see what i’m trying :wink:

Problem 2: I want to have a random error message. It does work but shows the error var name in the txtfield. Not the value of the var. See bold code. Also it doesn’t update/refresh when i click the submit button again. I know it’s a small bug, but just can’t find the solution atm, i’ve been working on it all day, became a little blurry :wink:

**Optional: **How hard is it to show on what row the error is? X or Y axis? It’s not a must have, but it would be a nice and usefull feature.

Thanks in advance!

Cheers,
Xs