2013-02-17 142 views
0

好吧,所以我是一个总noob。我想用任何键盘按钮在as3中推进一个场景。这是我的代码,你能帮我吗?As3键盘事件

import flash.events.Event; 
stage.addEventListener(MouseEvent.CLICK, startGame); 
addEventListener(Event.ENTER_FRAME, asteroidMovement); 
stage.addEventListener(KeyboardEvent.KEY_DOWN, startGameWithKeys); 

stop(); 


function startGameWithKeys(e:KeyboardEvent){ 
    removeEventListener(Event.ENTER_FRAME, asteroidMovement); 
    stage.removeEventListener(MouseEvent.CLICK, startGame); 
    gotoAndStop(1, "Scene 2"); 
} 

function startGame(e:MouseEvent) 
{ 
    removeEventListener(Event.ENTER_FRAME, asteroidMovement); 
    stage.removeEventListener(MouseEvent.CLICK, startGame); 
    gotoAndStop(1, "Scene 2"); 
} 

回答

0

您的监听程序代码很好,只要按任意键就应该进行调度。您的场景可能被错误地命名。

无论如何,总是尝试避免在Flash中使用场景。如果使用相框,使您在闪光灯IDE中感觉更舒适,但始终避免出现场景。下一步应该是使用开发IDE像FlashBuilder,避免时间轴代码:)

0

没有必要建立类似的行动,使用下面的代码两种功能,

而且跳跃到现场陈述是完美的。

function startGame(e:Event):void 
{ 
    //Put your code here 
    trace(e.type); 

    gotoAndStop(1, "Scene 2"); 
} 

stage.addEventListener(MouseEvent.CLICK, startGame, false, 0, true); 
stage.addEventListener(KeyboardEvent.KEY_DOWN, startGame, false, 0, true);