# Using onKeyDown within a class to call a function

**URL:** <https://forum.kirupa.com/t/using-onkeydown-within-a-class-to-call-a-function/217046>\
**Category:** flash\
**Created:** [February 22, 2007, 4:16pm UTC](https://forum.kirupa.com/t/using-onkeydown-within-a-class-to-call-a-function/217046 "2007-02-22T16:16:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luftbuefel](https://avatars.discourse-cdn.com/v4/letter/l/a88e4f/32.png) [@luftbuefel](https://forum.kirupa.com/u/luftbuefel)\
**Post date:** [February 22, 2007, 4:16pm UTC](https://forum.kirupa.com/t/using-onkeydown-within-a-class-to-call-a-function/217046/1 "2007-02-22T16:16:51Z")

</div>

Hello, I’m having a bit of trouble with some of the functions in a class I am making. I want to see if a button was pressed, then change some variables, and finally call the update function. My problem is that I cannot call the function updateit() once a key has been pressed. Here’s the simplified code:

public function updateit():Void{  
trace(“updateit worked”);  
}

public function navigate():Void {  
var myListener = new Object();  
myListener.onKeyDown = function() {  
if (Key.isDown(Key.RIGHT)) {  
//change some variables  
trace(“right”);  
updateit();  
}  
if (Key.isDown(Key.LEFT)) {  
//change some variables  
updateit();  
}  
if (Key.isDown(Key.UP)) {  
//change some variables  
updateit();  
}  
if (Key.isDown(Key.DOWN)) {  
//change some variables  
updateit();  
}  
};  
Key.addListener(myListener);  
}
