Ryan_28
09-26-2009, 08:24 AM
I'm working a flash chess game and ive managed to create the board, pieces and code that allows the pieces to be moved around the board. However, I'm still new to flash and programming in general and i dont know how to write the code that will make the chess pieces dissapear when they are taken by the opponent. Here is my code (albeit the code i ripped from the tutorial in flash help)
function restartMovie(event:MouseEvent):void
{
this.gotoAndStop(1);
}
playButton.addEventListener(MouseEvent.CLICK, restartMovie);
import flash.display.DisplayObject;
import flash.events.MouseEvent;
var offsetX:Number;
var offsetY:Number;
var draggedObject:DisplayObject;
function startDragging(event:MouseEvent):void
{
draggedObject = DisplayObject(event.target);
offsetX = event.stageX - draggedObject.x;
offsetY = event.stageY - draggedObject.y;
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}
function stopDragging(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}
function dragObject(event:MouseEvent):void
{
draggedObject.x = event.stageX - offsetX;
draggedObject.y = event.stageY - offsetY;
event.updateAfterEvent();
}
pawn_black_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_3.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_3.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_4.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_4.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_5.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_5.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_6.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_6.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_7.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_7.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_8.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_8.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_3.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_3.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_4.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_4.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_5.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_5.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_6.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_6.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_7.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_7.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_8.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_8.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_black_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_black_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_black_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_black_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_white_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_white_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_white_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_white_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
knight_black_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_black_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_black_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_black_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_white_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_white_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_white_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_white_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_black_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_black_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_black_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_black_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_white_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_white_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_white_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_white_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
queen_black.addEventListener(MouseEvent.MOUSE_DOWN , startDragging);
queen_black.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
queen_white.addEventListener(MouseEvent.MOUSE_DOWN , startDragging);
queen_white.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
king_black.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
king_black.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
king_white.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
king_white.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
stop();
if you would like to see the chess board and how it functions at current you can see it http://www.zeldaocarina.co.uk just scroll to the bottom of the website where you will see the chess game.
If anyone can help me out with this i will be very grateful.
Thank you
function restartMovie(event:MouseEvent):void
{
this.gotoAndStop(1);
}
playButton.addEventListener(MouseEvent.CLICK, restartMovie);
import flash.display.DisplayObject;
import flash.events.MouseEvent;
var offsetX:Number;
var offsetY:Number;
var draggedObject:DisplayObject;
function startDragging(event:MouseEvent):void
{
draggedObject = DisplayObject(event.target);
offsetX = event.stageX - draggedObject.x;
offsetY = event.stageY - draggedObject.y;
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}
function stopDragging(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}
function dragObject(event:MouseEvent):void
{
draggedObject.x = event.stageX - offsetX;
draggedObject.y = event.stageY - offsetY;
event.updateAfterEvent();
}
pawn_black_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_3.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_3.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_4.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_4.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_5.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_5.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_6.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_6.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_7.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_7.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_black_8.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_black_8.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_3.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_3.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_4.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_4.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_5.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_5.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_6.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_6.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_7.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_7.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
pawn_white_8.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
pawn_white_8.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_black_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_black_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_black_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_black_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_white_1.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_white_1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
rook_white_2.addEventListener(MouseEvent.MOUSE_DOW N, startDragging);
rook_white_2.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
knight_black_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_black_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_black_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_black_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_white_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_white_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
knight_white_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
knight_white_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_black_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_black_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_black_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_black_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_white_1.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_white_1.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
bishop_white_2.addEventListener(MouseEvent.MOUSE_D OWN, startDragging);
bishop_white_2.addEventListener(MouseEvent.MOUSE_U P, stopDragging);
queen_black.addEventListener(MouseEvent.MOUSE_DOWN , startDragging);
queen_black.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
queen_white.addEventListener(MouseEvent.MOUSE_DOWN , startDragging);
queen_white.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
king_black.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
king_black.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
king_white.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
king_white.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
stop();
if you would like to see the chess board and how it functions at current you can see it http://www.zeldaocarina.co.uk just scroll to the bottom of the website where you will see the chess game.
If anyone can help me out with this i will be very grateful.
Thank you