AS3 - Clicked object
I have this function to create a new element to a bidimensional array.
function addPiece (row, col, newPiece, elem)
{
newPiece.row = row;
newPiece.col = col;
newPiece.name = arr[elem];
grid[row][col] = newPiece;
newPiece.addEventListener(MouseEvent.CLICK,clickPiece);
return newPiece;
}
elem is picking randomally from an array of movieclips.
elem = Math.ceil(Math.random()*max) - 1;
var type:* = new arr[elem] as arr[elem];
gameSprite.addChild(addPiece(row, col, type, elem));
I want in this function to create a variable of the same type as the clicked movieclip but I can't figure out how to do that:
something like:
function clickPiece(event:MouseEvent)
{;
var piece:Piece = Piece(event.currentTarget);
}
