OK folks, I have a problem with that game I’m doing for the battle (don’t laugh). I have this function in the main timeline:
function listenForKeys(){
if (Key.isDown(Key.RIGHT)){
hero.xmov+=hero.moveIncrement;
}
if (Key.isDown(Key.LEFT)){
hero.xmov-=hero.moveIncrement;
}
if (Key.isDown(Key.UP)){
hero.ymov-=hero.moveIncrement;
}
if (Key.isDown(Key.DOWN)){
hero.ymov+=hero.moveIncrement;
}
if (Key.isDown(Key.SPACE)){
missileLaunch();
}
}
and I call it onEnterFrame, so that when I press and hold space, a new missile is launched. Which is not very realistic. What I’d like to do is set a maximum frequency for the missiles.
I thought about setInterval, but I would need to detect the moment I release the space key to clear the interval.
no it wont clear the interval unless space is not pressed [if(!Key.isDown(Key.SPACE))]. If you release an arrow key, yes, the onKeyUp will be called, but the interval will no be cleared unless the SPACE is not being pressed… and if its not the key being released, it wont matter because the interval wont be set anyway.