[英]Key pressed + gotoAndPlay(xy) Flash
我正在制作帶有2個動畫的Flash游戲。 站立動畫和移動動畫。 我希望如果有人按下上下左右箭頭,然后播放移動動畫,並且如果未按下這些鍵,則播放站立動畫。
我用了:
stage.addEventListener(KeyboardEvent.KEY_DOWN, movingAnimation);
function movingAnimation(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
account_animation.gotoAndPlay("moving");
}
if (event.keyCode == 38)
{
account_animation.gotoAndPlay("moving");
}
if (event.keyCode == 39)
{
account_animation.gotoAndPlay("moving");
}
if (event.keyCode == 40)
{
account_animation.gotoAndPlay("moving");
}
}
stage.addEventListener(KeyboardEvent.KEY_UP, standingAnimation);
function standingAnimation(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
account_animation.gotoAndPlay("standing");
}
if (event.keyCode == 38)
{
account_animation.gotoAndPlay("standing");
}
if (event.keyCode == 39)
{
account_animation.gotoAndPlay("standing");
}
if (event.keyCode == 40)
{
account_animation.gotoAndPlay("standing");
}
}
這是行不通的。 我在這里做錯了什么?
目前,您的代碼沒有任何問題。 您應該驗證以下幾點:
在預覽時,請單擊swf(也許您沒有在該窗口中被選中,因此不會觸發鍵盤事件。)
確保動畫框架標簽正確。
檢查account_animation
是執行gotoAndPlay的正確資產。
我測試了您的代碼以驗證其是否正常運行,因此您需要驗證資產和時間軸設置,以確保所有設置均正確無誤,因為我們無法在fla文件中看到您的時間軸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.