That's more than needed. You only want to run the code when the key is pressed. What you have there keeps checking multiple times a second. Try something like:
Code:
var keypressed = false;
var key:Object = {
onKeyDown:function() {
if(!keypressed){
keypressed=true;
switch(Key.getCode()) {
case Key.LEFT:
trace('decrease var');
break;
case Key.RIGHT:
trace('increase var');
break;
}
}
},
onKeyUp:function() {
keypressed = false;
}
};
Key.addListener(key);
I did some looking around and this I feel is the best way to handle listeners in this case. I tested it so this works with as2.