在 Flash 中使用 ActionScript 3.0 计算点击次数
我想根据点击次数更改变量值。
因此,如果单击按钮一次,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);
}
}
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.
Right now all I'm returning for the value is 0, no matter the amount of clicks.
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cCount
是局部变量吗?换句话说,您在每次加载框架时都会调用的函数中发布的代码是吗?添加两个跟踪语句以查看发生了什么:
Is
cCount
a local variable? 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:
只要您在函数外部声明 cCount 变量,它就会保持准确的计数。否则,每次点击都会重置它。
As long as you declare the cCount variable outside of your function, it will keep an accurate count. Otherwise, it gets reset on each click.