Keyboard event for the ENTER key

Hi,

I have a button on the stage called enterCostBtn that when it is pressed it executes the code inside the calculateCost function. What I want to do is to be able to use the ENTER key on my keyboard to trigger that function. In other words I would like to be able to use the ENTER key or click directly on the enterCostBtn to trigger this function.


enterCostBtn.addEventListener(MouseEvent.CLICK,calculateCost,false,0,true);

function calculateCost(event:MouseEvent):void {
	var material:Number=Number(Material_txt.text);
	var labor:Number=Number(Labor_txt.text);
	var percent:Number=Number(Percent_txt.text);
	var purchasePlusLabor=material+labor;
	var plusPercent=labor*percent/100;
	var totalCost=purchasePlusLabor+plusPercent;

	txtCost.text=String("$  "+totalCost);

	trace(purchasePlusLabor + "     Purchase Plus Labor");
	trace(totalCost + "    Total Cost");
}

I tried something like this but it doesn’t work.

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
function onKeyPressed(evt:KeyboardEvent):void {

	switch (evt.keyCode) {
		case Keyboard.ENTER :
			calculateCost();
			break;

	}
}

Can someone try to help me with this? As always thank you for your help!