所以有人知道为什么它不起作用吗?我想在我的八哥班上听关键事件,我需要集中注意力吗?如果是,我该怎么做?这是一个 Main 类,这是文档类:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import starling.core.Starling;
public class Main extends Sprite{
private var starling:Starling
public function Main(){
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
private function init(e:Event = null):void{
removeEventListener(Event.ADDED_TO_STAGE, init);
starling = new Starling(ScreenCoorder, stage);
starling.start();
}
}
}
和 screencorder 类(从八哥开始):
package
{
import starling.display.Sprite;
import starling.events.Event;
import starling.events.KeyboardEvent;
public class ScreenCoorder extends Sprite{
public function ScreenCoorder() {
super();
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void {
removeEventListener(Event.ADDED_TO_STAGE, init);
this.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
}
public function onDown(e:KeyboardEvent):void {
trace("so serious");
}
}
}