# Why won't my character move with the arrow keys in Actionscript 3?

**URL:** <https://forum.kirupa.com/t/why-wont-my-character-move-with-the-arrow-keys-in-actionscript-3/310348>\
**Category:** flash\
**Created:** [June 8, 2010, 5:13am UTC](https://forum.kirupa.com/t/why-wont-my-character-move-with-the-arrow-keys-in-actionscript-3/310348 "2010-06-08T05:13:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SupehManz](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@SupehManz](https://forum.kirupa.com/u/SupehManz)\
**Post date:** [June 8, 2010, 5:13am UTC](https://forum.kirupa.com/t/why-wont-my-character-move-with-the-arrow-keys-in-actionscript-3/310348/1 "2010-06-08T05:13:52Z")

</div>

\*\*[SIZE=2][/SIZE] \*\*

My character’s name is character. When left and right are pressed it tells me what’s being pressed when I run it - it says there’s no errors with the code. My character doesn’t do anything though! This is the code i used:

//defining variables  
var leftKeyDown:Boolean = false;  
var rightKeyDown:Boolean = false;  
var xspeed:Number = 10  
//checks if keys is being pressed  
function checkKeys(event:KeyboardEvent) {  
if (event.keyCode == 39) {  
trace(“Right key is down”);  
rightKeyDown = true;  
}  
if (event.keyCode == 37) {  
trace(“Left key is down”);  
leftKeyDown = true;  
}  
}  
//checks if keys is being released  
function keyUps(event:KeyboardEvent) {  
if (event.keyCode == 39) {  
event.keyCode = 0;  
rightKeyDown=false;  
trace(“Right key is NOT down”);  
}  
if (event.keyCode == 37) {  
event.keyCode = 0;  
leftKeyDown=false;  
trace(“Left key is NOT down”);  
}  
}  
//chracters movement  
function movement(Event){  
if (rightKeyDown == true) {  
character.x += xspeed;  
}  
if (rightKeyDown == true) {  
character.x -= xspeed;  
}  
}  
//add listeners  
stage.addEventListener(Event.ENTER\_FRA… movement);  
stage.addEventListener(KeyboardEvent.K… , checkKeys);  
stage.addEventListener(KeyboardEvent.K… keyUps);

The character is a movie clip, it has the right instance name so I dont know what’s wrong.

The actions are on one layer and the character is on another if this helps.
