ActionScript 3 听导航键

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 听导航键相关的知识,希望对你有一定的参考价值。

private var goRight:Boolean = false;
private var goLeft:Boolean = false;
private var goDown:Boolean = false;
private var goUp:Boolean = false;


public function Main() 
{
	stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
	stage.addEventListener(KeyboardEvent.KEY_UP, upHandler);
}
	
private function keyHandler(e:KeyboardEvent):void 
{
	switch (e.keyCode) 
	{
		case Keyboard.UP:
			goUp = true;
		break;
		
		case Keyboard.DOWN:
			goDown = true;
		break;
		
		case Keyboard.LEFT:
			goLeft = true;
		break;
		
		case Keyboard.RIGHT:
			goRight = true;
		break;	
		
		default:
			trace(e.keyCode);
		break;
	}
}
	
	
private function upHandler(e:KeyboardEvent):void 
{
	switch (e.keyCode) 
	{
		case Keyboard.UP:
			goUp = false;
		break;
			
		case Keyboard.DOWN:
			goDown = false;
		break;
			
		case Keyboard.LEFT:
			goLeft = false;
		break;
	
		case Keyboard.RIGHT:
			goRight = false;
		break;	
	
		default:
			trace(e.keyCode);
		break;
}

以上是关于ActionScript 3 听导航键的主要内容,如果未能解决你的问题,请参考以下文章

Actionscript 导航不起作用

ActionScript 3 导航到URL。调用可选的javascript弹出窗口

ActionScript 3 使用AS3和Tweenlite的Spotlight导航效果

如何检测 Actionscript 3 中是不是按下了删除键?

ActionScript 3 AS3右键菜单

ActionScript 3 按F5键重新加载Firefox