# Taking Piece Chess Problem

**URL:** <https://forum.kirupa.com/t/taking-piece-chess-problem/329357>\
**Category:** flash\
**Created:** [August 17, 2012, 2:36am UTC](https://forum.kirupa.com/t/taking-piece-chess-problem/329357 "2012-08-17T02:36:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WarChimp](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@WarChimp](https://forum.kirupa.com/u/WarChimp)\
**Post date:** [August 17, 2012, 2:36am UTC](https://forum.kirupa.com/t/taking-piece-chess-problem/329357/1 "2012-08-17T02:36:30Z")

</div>

Hello,

I have been making a chess flash game for the past x amount of time. However I have encountered a problem when I take a piece. I cannot work out how to actually take the piece.

Here is my code  
This is the function that handles the move

```php

function handleMove(type:String, piece:String, xpos:int, ypos:int)
{
 switch (type)
 {
  case "up":
   heldPiece = chessPieces[ypos][xpos];
   chessPieces[ypos][xpos] = "0"
  break;
  case "down":
   takePiece(heldPiece, xpos, ypos, piece);
   clearBoard(piece);
  break;
 }
 trace(chessPieces);
 trace("(" + xpos + " , " + ypos + ") - " + piece + " - " + type)
}

```

Within the case “down” calls the takePiece function and the clearBoard function they are as follows:

```php

function takePiece(heldPiece:int, xpos:int, ypos:int, piece:String)
{
 if(chessPieces[ypos][xpos] == "0")
 {
  chessPieces[ypos][xpos] = heldPiece;
 } else {
  takenPiece = chessPieces[ypos][xpos];
  trace(takenPiece);
  chessPieces[ypos][xpos] = heldPiece;
 }
}

```

```php

function clearBoard(piece:String)
{
 removeChild(BpawnChess);
}

```

This is giving me an error

> Implicit coercion of a value of type Class to an unrelated type flash.display: DisplayObject.

I had planned to take the piece and basically redraw the chessPieces array in a new position, since there are only 32 pieces it shouldn’t cause any lag.

I honestly don’t know what to do. If you need anything else for clarification let me know.

Thanks

WarChimp
