【问题标题】:Key pressed + gotoAndPlay(xy) Flash按键 + gotoAndPlay(xy) Flash
【发布时间】:2014-01-15 01:02:49
【问题描述】:

我正在制作一个带有 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");
    }
}

这不起作用。我在这里做错了什么?

【问题讨论】:

  • 这段代码在你的时间线上我接受吗?

标签: actionscript-3 flash


【解决方案1】:

目前您的代码没有任何问题。您应该验证几件事:

  • 在预览时单击您的 swf(可能未在该窗口中选择您,因此键盘事件不会触发。)

  • 确保动画帧标签正确。

  • 检查 account_animation 是否是执行 gotoAndPlay 的正确资产。

我测试了您的代码以验证它是否正常工作,因此您需要验证您的资产和时间线设置以确保所有这些都是正确的,因为我们无法在您的 fla 文件中看到您的时间线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    相关资源
    最近更新 更多