as3重置'numPressed'功能

时间:2012-11-17 15:43:37

标签: actionscript-3

我对as3很新,所以对你们大多数人来说这可能是非常明显的:P 我正在使用numPressed函数(计算鼠标点击次数),需要在第6次点击后重置鼠标点击次数... 这就是代码的样子:

var numPressed:Number = 0;
any_mc.addEventListener(MouseEvent.CLICK, countUp);
function countUp(evt:MouseEvent):void {
numPressed++;

if (numPressed == 1) {
any_mc.gotoAndPlay(1);
}
else if (numPressed == 2) {
any_mc.gotoAndPlay(2);
}

else if (numPressed == 3) {
any_mc.gotoAndPlay(3);
}

else if (numPressed == 4) {
any_mc.gotoAndPlay(4);
}

else if (numPressed == 5) {
any_mc.gotoAndPlay(5);
}
}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

如同Taurayi所说,但你也可以像这样清理一下你的功能。

function countUp(evt:MouseEvent):void 
{
    any_mc.gotoAndPlay(numPressed++);

    if(numPressed > 5)
        numPressed = 1;
}