尝试在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帧?
发布于 2021-11-17 20:08:27
请原谅我生疏的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;
}https://stackoverflow.com/questions/70009461
复制相似问题