【问题标题】:actionscript - 如何让 Key.isDown 停止!按?
【发布时间】:2021-12-28 17:30:59
【问题描述】:

尝试在 Flash 中制作简单的漫画。按向左或向右箭头键,您将转到漫画的下一帧。问题是我按一次右键,它会立即循环播放整个漫画。

第 1 帧

    stop();
onEnterFrame = function(){

if(Key.isDown(Key.RIGHT))
    {
        
        gotoAndStop(2);
    }
}

第 2 帧

    stop() ;
onEnterFrame = function(){

if(Key.isDown(Key.RIGHT))
    {
        
        gotoAndStop(3);
    }
if(Key.isDown(Key.LEFT))
{
    gotoAndStop(1);
    }
    
}

等等等等

我要如何做到这一点,所以你按下右键,它会进入第 2 帧并停止,只有在你将手指从右键上移开并再次按下它时才会进入第 3 帧?

【问题讨论】:

    标签: flash adobe actionscript-2


    【解决方案1】:

    原谅我生疏的AS2,距离我上一次认真使用它已经过去10多年了,但它背后的逻辑应该是扎实的。您需要为这两个键设置一个标志来跟踪它们之前是否被按下,然后您应该仅在上次未按下相关键时向左或向右浏览页面,但现在是。

    // Frame 1. You only need this script, it will serve
    // the whole timeline. You don't need other scripts on other frames.
    
    // These are flags to know, if the relevant keys was pressed previously.
    var wasLeft:Boolean;
    var wasRight:Boolean;
    
    function onEnterFrame()
    {
        var isLeft:Boolean = Key.isDown(Key.LEFT);
        var isRight:Boolean = Key.isDown(Key.RIGHT);
        
        // Move to the previous page only if
        // the LEFT key is but wasn't pressed
        // and also if the other button is up.
        if (isLeft && !wasLeft && !isRight)
        {
            prevFrame();
        }
        
        // The same routine for the other key.
        if (isRight && !wasRight && !isLeft)
        {
            nextFrame();
        }
        
        // Keep the present state of things for the next frame call.
        wasLeft = isLeft;
        wasRight = isRight;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-07
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2023-01-22
      • 1970-01-01
      • 2012-07-14
      • 2015-05-23
      • 2011-06-05
      相关资源
      最近更新 更多