使用Flash中的actionscript 3.0计算点击次数

时间:2010-03-17 04:52:29

标签: flash actionscript-3 flash-cs4

我想根据点击次数更改变量值。

因此,如果您单击按钮一次,则cCount应等于1,两次应等于2.

现在,无论点击量多少,我返回的值都是0。

有什么想法吗?

btnRaw.addEventListener(MouseEvent.CLICK, flip);
btnRaw.addEventListener(MouseEvent.MOUSE_UP,count);
//create the flipping function

//create the variable to store the click count
var cCount:Number = 0;

function flip(Event:MouseEvent):void{
    raw_patty_mc.gotoAndPlay(1);
}

function count(Event:MouseEvent):void{
    cCount = cCount+1;
    if(cCount>3 || cCount<6){
        titleText.text="See you're doing a great job at flipping the burger! "+String(cCount);
    }
}

2 个答案:

答案 0 :(得分:1)

cCount是局部变量吗?换句话说,是您在每次加载帧时调用的函数内发布的代码吗?

添加两个跟踪语句以查看发生的情况:

function count(Event:MouseEvent):void{
    trace("before " + cCount); //?
    cCount = cCount+1;
    trace("after " + cCount);  //?
    if(cCount>3 || cCount<6){
        titleText.text="See you're doing a great job at flipping the burger! "+String(cCount);
    }
}

答案 1 :(得分:0)

只要在函数之外声明cCount变量,它就会保持准确的计数。否则,每次点击都会重置。

相关问题