# Keyboard input not working

**URL:** <https://forum.kirupa.com/t/keyboard-input-not-working/316416>\
**Category:** Uncategorized\
**Created:** [November 20, 2010, 7:08pm UTC](https://forum.kirupa.com/t/keyboard-input-not-working/316416 "2010-11-20T19:08:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WEich1213](https://avatars.discourse-cdn.com/v4/letter/w/ecb155/32.png) [@WEich1213](https://forum.kirupa.com/u/WEich1213)\
**Post date:** [November 20, 2010, 7:08pm UTC](https://forum.kirupa.com/t/keyboard-input-not-working/316416/1 "2010-11-20T19:08:54Z")

</div>

can’t figure out why the keyboard input isn’t working. I got this warning, but I always get that warning and it always works. The warning says:

Warning: 1090: Migration issue: The onKeyDown event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( ‘keyDown’, callback\_handler).

don’t know what the warning means or how to do what it says, or even if it’s related to the problem.

Here’s the code:

package {  
import flash.display.MovieClip;  
import flash.display.Bitmap;  
import flash.display.BitmapData;  
import flash.events.KeyboardEvent;  
import flash.ui.Keyboard;  
import flash.events.Event;

```
public class PlayerShip extends MovieClip
{
	private const SPEED:Number = .4;
	public static var gravity:Number = .025;
	public var _player:Bitmap;
	private var _vx:Number = 0;
	private var _vy:Number = 0;
	private var _stageWidth:Number;
	private var	_stageHeight:Number;
	
	
	public function PlayerShip()
	{
		addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
	}
	private function onAddedToStage(event:Event):void
	{ 
	
		//Initialize properties
		_player = new Bitmap;
		
		_stageWidth= stage.stageWidth;
		_stageHeight= stage.stageHeight;
		
		
		//Add event listenters
		
		stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
		stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		
		
		addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
	}
	private function onRemovedFromStage(event:Event):void
	{
		
		removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage)
	}
	
	
	public function onKeyDown(event:KeyboardEvent):void
	{
		switch (event.keyCode)
		{
		  case Keyboard.LEFT:
		    _vx -= SPEED *.5;
		    break;
		    
		  case Keyboard.RIGHT:
		  _vx += SPEED * .5;
		    break;
		    
		  case Keyboard.UP:
			_vy -= SPEED;
		  break;
		  
		case Keyboard.DOWN:
		  
		  break;
		}
	}
	
	public function onKeyUp(event:KeyboardEvent):void
{
	if (event.keyCode == Keyboard.LEFT 
	|| event.keyCode == Keyboard.RIGHT)
	{
	   //_vx = 0;
	  }
	  
	  if (event.keyCode == Keyboard.UP 
	  || event.keyCode == Keyboard.DOWN)
	{
	   //_vy = 0;
	  }
	  
	  
	 
}

	
	
	
	
	
	
	public function frameEvents():void
	{//Directives....
		scrollWithPlayer();
		
		
	}
	
	
	public function scrollWithPlayer()
	{
		//trace(_vx);
		_player = Lunar_Madness.Player;
		_player.x += _vx;
		_player.y += _vy;
		_vy += gravity;
		
		
	}
	
	
	
	
	
	
}

```

}
