简体   繁体   English

按键+ gotoAndPlay(xy)Flash

[英]Key pressed + gotoAndPlay(xy) Flash

I'm making a flash game with 2 animation. 我正在制作带有2个动画的Flash游戏。 A standing animation and a moving animation. 站立动画和移动动画。 I want that if someone press up-down-left-right arrow then play moving animation, and if these keys aren't pressed then play standing animation. 我希望如果有人按下上下左右箭头,然后播放移动动画,并且如果未按下这些键,则播放站立动画。

I used: 我用了:

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");
    }
}

This is not working. 这是行不通的。 What am i doing wrong here? 我在这里做错了什么?

Currently there is nothing wrong with your code. 目前,您的代码没有任何问题。 You should verify a few things: 您应该验证以下几点:

  • Click on your swf when it's being previewed ( perhaps you are not selected in that window so the keyboard events are not firing. ) 在预览时,请单击swf(也许您没有在该窗口中被选中,因此不会触发键盘事件。)

  • Make sure the animation frame labels are correct. 确保动画框架标签正确。

  • Check that account_animation is the correct asset to be doing the gotoAndPlay on. 检查account_animation是执行gotoAndPlay的正确资产。

I tested your code to verify that it is working properly, so you'll need to verify your asset and timeline setup to make sure all of that is correct since we cannot see your timeline in your fla file. 我测试了您的代码以验证其是否正常运行,因此您需要验证资产和时间轴设置,以确保所有设置均正确无误,因为我们无法在fla文件中看到您的时间轴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM