# \[FMX04\] Key.addlistener?

**URL:** <https://forum.kirupa.com/t/fmx04-key-addlistener/104514>\
**Category:** Uncategorized\
**Created:** [March 17, 2004, 12:37am UTC](https://forum.kirupa.com/t/fmx04-key-addlistener/104514 "2004-03-17T00:37:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cookie](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cookie](https://forum.kirupa.com/u/cookie)\
**Post date:** [March 17, 2004, 12:37am UTC](https://forum.kirupa.com/t/fmx04-key-addlistener/104514/1 "2004-03-17T00:37:43Z")

</div>

I’m having trouble getting this part of Sen’s code to function! I attached his tutorial fla! I’ve searched in the AS help in Flash and tried modifying the Key.addlistener object but it still won’t respond to the arrow keys!

Sen’s code

```php
// set the ball to recognize key presses and move based on them
Key.addListener(ball);
ball.onKeyDown = function(){
	var xmove, ymove;
	if (Key.isDown(Key.UP)){
		ymove = 1;
	}else if (Key.isDown(Key.DOWN)){
		ymove = -1;
	}else if (Key.isDown(Key.LEFT)){
		xmove = -1;
	}else if (Key.isDown(Key.RIGHT)){
		xmove = 1;
	}
	// update new position based on ball's current
	xmove += this.x;
	ymove += this.y;
	if (IsValidTile(xmove, ymove)){
		moveToGridSpace(xmove, ymove);
	}
}

```

My attempt

```php
// set the ball to recognize key presses and move based on them
ball = new Object ();
ball.onKeyDown = function(){
	var xmove, ymove;
	if (Key.isDown(Key.UP)){
		ymove = 1;
	}else if (Key.isDown(Key.DOWN)){
		ymove = -1;
	}else if (Key.isDown(Key.LEFT)){
		xmove = -1;
	}else if (Key.isDown(Key.RIGHT)){
		xmove = 1;
	}
Key.addListener(ball);
	// update new position based on ball's current
	xmove += this.x;
	ymove += this.y;
	if (IsValidTile(xmove, ymove)){
		moveToGridSpace(xmove, ymove);
	}
}

```

What is wrong?
