[英]count clicks using actionscript 3.0 in flash
I want to change the variable value based on the number of clicks. 我想根据点击次数更改变量值。
So if you click the button once, the cCount should equal 1 and twice it should equal 2. 因此,如果单击一次按钮,则cCount应该等于1,两次应该等于2。
Right now all I'm returning for the value is 0, no matter the amount of clicks. 现在,无论点击多少,我返回的值都是0。
Any ideas? 有任何想法吗?
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);
}
}
Is cCount
a local variable? cCount
是局部变量吗? In other words, is the code that you posted inside a function that is called every time the frame loads? 换句话说,您在框架中加载的代码是否在每次加载框架时都会调用?
Add two trace statements to see what is happening: 添加两个跟踪语句以查看正在发生的情况:
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);
}
}
As long as you declare the cCount variable outside of your function, it will keep an accurate count. 只要您在函数外部声明cCount变量,它就会保持准确的计数。 Otherwise, it gets reset on each click.
否则,它将在每次点击时重置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.