基本上我试图在我的程序中几乎不添加键盘事件侦听器,然后开始迭代地构建它们。问题是,即使是从多个教程中获得最简单的东西,显然也是个问题。我不太确定我现在缺少什么。我试过添加东西、改变东西和取出东西。但是鉴于以下代码,我看不到屏幕上显示任何消息。为什么?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:local="*" xmlns:mx="http://www.adobe.com/2006/mxml" width="480" height="600" layout="absolute" creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.KeyboardEvent;
private function onStart(pEvent:Event):void {
vs.selectedChild = mm;
}
private function onNewGame(pEvent:Event):void {
vs.selectedChild = game;
}
private function onCreationComplete():void {
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addEventListener(KeyboardEvent.KEY_UP, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyDown);
}
private function onKeyDown(pEvent:KeyboardEvent):void {
Alert.show("spam");
Alert.show(pEvent.toString());
}
]]>
</mx:Script>
<mx:ViewStack id="vs" creationComplete="vs.selectedChild = ts">
<local:TitleScreen id="ts" creationComplete="ts.addEventListener(TitleScreen.START, onStart);" />
<local:MainMenu id="mm" creationComplete="mm.addEventListener(MainMenu.NEW_GAME, onNewGame);" />
<local:Game id="game" />
</mx:ViewStack>
</mx:Application>