# Keyboard events within a class in as3

**URL:** <https://forum.kirupa.com/t/keyboard-events-within-a-class-in-as3/289896>\
**Category:** Uncategorized\
**Created:** [June 6, 2009, 3:25pm UTC](https://forum.kirupa.com/t/keyboard-events-within-a-class-in-as3/289896 "2009-06-06T15:25:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radica1Faith](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@Radica1Faith](https://forum.kirupa.com/u/Radica1Faith)\
**Post date:** [June 6, 2009, 3:25pm UTC](https://forum.kirupa.com/t/keyboard-events-within-a-class-in-as3/289896/1 "2009-06-06T15:25:39Z")

</div>

seem to have trouble getting a keyboard event within a class to work, I have an ENTER\_FRAME event which works fine, but the keyboard event never gets called. Any ideas? here’s the code package  
{  
import flash.display.MovieClip;  
import flash.display.Stage;  
import flash.events.\*;  
public class mainGame extends MovieClip  
{  
var myPlayer:player = new player();  
function mainGame():void  
{  
trace(“arg!”);  
addChild(myPlayer);  
addEventListener(KeyboardEvent.KEY\_DOWN, keyDown);  
addEventListener(Event.ENTER\_FRAME, update);  
}  
function keyDown(evt:KeyboardEvent):void  
{  
trace(“This never happens”);  
myPlayer.x++;  
}  
function update(evt:Event):void  
{  
trace(“This happens fine”);  
}

}  
}  
thanks in advance!
