0 Replies Latest reply on Aug 9, 2010 1:24 AM by iban08

    problems with drawing childrens in my canvas.

    iban08

      Hi,

       

      I was trying to develop a simple game in AS3 and by now everything works, but now i have a problem that i can't fix. I don't know why it occurs and i don't know exactly how to explain it, but I'll try.

       

      I started following the tutorial from the adobe site for " Building a game with Flash Builder using the Cairngorm framework" from this page http://www.adobe.com/devnet/flex/articles/four_in_a_row.html, but it is not finished yet and I've tried to add some new functions by myself.

       

      my problem was now that I started the game (4 in a row game) and it works fine, when a player wins he can choose between restarting the game, or see the High Scores Table, for what I've added two buttons in the Board of the game when someone wins. After that if he choose to look for the High Score Table, I've added the same 2 buttons in this new view where the player can choose to restart the game again from here.

       

      I use the only 2 functions to draw the graphics on the canvas, one for the game Board (inside the boardCanvas.mxml file) and the other one for the High Scores Table (in the HSCanvas.mxml), I call this functions one time and they worked, but the second time I try to call them the screen stays white, I only have 2 functions and I don't know how it can work one time and not other times. When I click on the button I know that the program enters on the drawBoard() or draHStable() functions, with the help of the debugger, but nothing appears on the screen.

       

      I hope my explanation will let you understand my problem and I'll be very thankful for receiving your help before i get crazy whit this.

       

      Thanks.

       

      i paste here some of my code if that can be helpful.

       

      public function drawBoard():void {

       

      // Clear the board canvas

      chipCanvas.removeAllChildren();

      backCanvas.removeAllChildren();

      frontCanvas.removeAllChildren();

       

       

      // Set the size of our main canvas

      this.width = 30 + (CELL_WIDTH * __model.board.getCols());

      this.height = 80 + (CELL_HEIGHT * __model.board.getRows());

       

      var BEB2:ArrayCollection = new ArrayCollection();

      var BEF2:ArrayCollection = new ArrayCollection();

       

       

      for (var r:int=__model.board.getRows()-1; r >= 0; r--) {

      // Loop through each row (bottom up to handle overlap)

      for (var c:int=__model.board.getCols()-1; c >= 0; c--) {

      // Loop through each col (right to left to handle overlap)

       

      // Create Back of cell

      var BEB:BoardElementBack = new BoardElementBack;

      BEB.x = 15 + (CELL_WIDTH * c);

      BEB.y = 15 + (CELL_HEIGHT * r);

      var bb2:UIComponent = new UIComponent;

      bb2.addChild(BEB);

      BEB2.addItem(bb2);

      backCanvas.addChild(UIComponent(BEB2.getItemAt(BEB2.length-1)));

       

      // Create Front of cell

      var BEF:BoardElementFront = new BoardElementFront;

      BEF.x = 15 + (CELL_WIDTH * c);

      BEF.y = 15 + (CELL_HEIGHT * r);

      var bf2:UIComponent = new UIComponent;

      bf2.addChild(BEF);

      BEF2.addItem(bf2);

      frontCanvas.addChild(UIComponent(BEF2.getItemAt(BEF2.length-1)));

      }

      }

       

      // Add score

       

      S.scoreDisplay.text="0";

      S.x = 60 + (CELL_WIDTH * 4);

      S.y = -25 + (CELL_HEIGHT * 0);

      gameScore=0;

      S2.addChild(S);

      frontCanvas.addChild(S2);

       

       

      }

       

      public function drawHSTable():void {//utilizando SWC

       

      // Clear the board canvas

      backCanvas.removeAllChildren();

      frontCanvas.removeAllChildren();

       

       

      // Set the size of our main canvas

      this.width = 30 + (CELL_WIDTH * __model.hs.getCols());

      this.height = 80 + (CELL_HEIGHT * __model.hs.getRows());

       

      HST.x = 315;

      HST.y = 250;

       

       

      HST2.addChild(HST);

      backCanvas.addChild(HST2);

       

       

      for (var r:int=__model.hs.getRows(); r > 0; r--) {

      for (var c:int=__model.hs.getCols(); c > 0; c--) {

       

      if (c == 1){

      var HSN:HSnombre = new HSnombre;

      var HSN2:UIComponent = new UIComponent;

       

      HSN.x = (CELDA_WIDTH * c) - 75;

      HSN.y = 20 + (CELDA_HEIGHT * r);

      HSN.nombre.text = "JUGADOR "+r;

       

      HSN2.addChild(HSN);

      frontCanvas.addChild(HSN2);

       

      nombres[r-1]=HSN.nombre.text;

      }

      else{

      var HSS:HSscore = new HSscore;

      var HSS2:UIComponent = new UIComponent;

       

      HSS.x = (CELDA_WIDTH * c) - 75;

      HSS.y = 20 + (CELDA_HEIGHT * r);

      HSS.score.text = "999999";

       

      HSS2.addChild(HSS);

      frontCanvas.addChild(HSS2);

       

      puntos[r-1]=HSS.score.text;

      }

      }

      }

       

      RSBtn.x = (CELDA_WIDTH * __model.hs.getCols())-400;

      RSBtn.y = 60 + (CELDA_HEIGHT * __model.hs.getRows());

       

      RSBtn2.addChild(RSBtn);

      frontCanvas.addChild(RSBtn2);

       

      HSBtn.x = (CELDA_WIDTH * __model.hs.getCols()) - 150;

      HSBtn.y = 60 + (CELDA_HEIGHT * __model.hs.getRows());

       

      HSBtn2.addChild(HSBtn);

      frontCanvas.addChild(HSBtn2);

       

      RSBtn2.addEventListener(MouseEvent.MOUSE_DOWN,__model.boardView.restartGame);

      HSBtn2.addEventListener(MouseEvent.MOUSE_DOWN,__model.boardView.showHighScores);

       

      }

       

      public function restartGame(e:MouseEvent):void{

       

      RSBtn2.removeEventListener(MouseEvent.MOUSE_DOWN,restartGame);

      HSBtn2.removeEventListener(MouseEvent.MOUSE_DOWN,showHighScores);

      __model.board.clearBoard();

      __model.boardView.drawBoard();

      __model.hsView.removeAllChildren();

      __model.boardView.init();

      }

       

       

      public function showHighScores(e:MouseEvent):void{

       

      RSBtn2.removeEventListener(MouseEvent.MOUSE_DOWN,restartGame);

      HSBtn2.removeEventListener(MouseEvent.MOUSE_DOWN,showHighScores);

      __model.board.clearBoard();

      __model.boardView.removeAllChildren();

      __model.hsView.drawHSTable();

      }