2013-02-17 198 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);