init();
//tttWinner
//this version can tell if somebody has won
//uses winningCombo array

function init(){
  //set up X values
  xVals = new Array(130, 230, 330, 130, 230, 330, 130, 230, 330);
  yVals = new Array(120, 120, 120, 210, 210, 210, 300, 300, 300);
  board = new Array("blank", "blank", "blank", "blank", "blank", 
                    "blank", "blank", "blank", "blank");
  turn = "x";

  //winningCombo is an array of all winning combos
  winningCombo = new Array(
    new Array(0, 1, 2),
    new Array(3, 4, 5),
    new Array(6, 7, 8),
    new Array(0, 3, 6),
    new Array(1, 4, 7),
    new Array(2, 5, 8),
    new Array(0, 4, 8),
    new Array(2, 4, 6)
  );

  //build classes from cell
  for (i = 0; i < 9; i++){
    _root.attachMovie("cell", "cell_" + i, 100 + i);
    theCell = eval("cell_" + i);
    theCell._x = xVals[i];
    theCell._y = yVals[i];
    theCell.state = "blank";
    theCell.index = i;
    theCell.gotoAndStop(theCell.state);
	  
    //add click event
    theCell.onMouseUp = function(){
      //respond only if mouse is over me (aaaargh!)
      if (this.hitTest(_root._xmouse, _root._ymouse, false)){
        currentSquare = this.index;
        if(board[currentSquare] == "blank"){
          board[currentSquare] = turn;
          this.state = turn;
          this.gotoAndStop(this.state);
          if (turn == "x"){
            turn = "o";
          } else {
            turn = "x";
          } // end 'whos turn' if
        } // end 'board is blank' if
        checkForWinner();
      } // end "hit this instance" if
    } // end mouseUp
  } // end for
} // end init

function checkForWinner(){
  //looks to see if the board matches any winning combos
  for (comboNum = 0; comboNum < 8; comboNum++){
    firstVal = winningCombo[comboNum][0];
    secondVal = winningCombo[comboNum][1];
    thirdVal = winningCombo[comboNum][2];
    if ((board[firstVal] == board[secondVal]) &&
        (board[secondVal] == board[thirdVal]) &&
        (board[firstVal] != "blank")){
      winner = board[firstVal];
      trace (winner + " wins!");
		  
    } // end if
  } // end for
} // end checkForWinner