# Keyboard event problem

**URL:** <https://forum.kirupa.com/t/keyboard-event-problem/297109>\
**Category:** Uncategorized\
**Created:** [September 25, 2009, 5:25pm UTC](https://forum.kirupa.com/t/keyboard-event-problem/297109 "2009-09-25T17:25:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kagamushu](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@kagamushu](https://forum.kirupa.com/u/kagamushu)\
**Post date:** [September 25, 2009, 5:25pm UTC](https://forum.kirupa.com/t/keyboard-event-problem/297109/1 "2009-09-25T17:25:05Z")

</div>

Hello,  
i have a button that triggers an event (subClick)  
I have added a keyboard event so that the user can press ENTER to also trigger subClick.  
Here is the problem, when i publish, i get the following error whether i click the button or press enter:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@3d69f601 to fl.controls.Button.

Also, for the keyboard to trigger the event, i have to press enter twice.  
I don’t know if the error and the fact that i have to press enter twice are related, any clues? thanks,  
Here is my code:

import fl.controls.Button;  
import flash.display.Stage;

import flash.ui.Keyboard;  
import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY\_DOWN, keyDownHandler);  
function keyDownHandler(event : KeyboardEvent) : void  
{  
if (event.keyCode == Keyboard.ENTER)  
{  
addEventListener(KeyboardEvent.KEY\_DOWN,subClick);  
}  
}

submit\_btn.addEventListener(MouseEvent.CLICK,subClick);
