在 Flash 中使用 ActionScript 3.0 计算点击次数

发布于 2024-08-25 09:37:36 字数 620 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧幽蓝 2024-09-01 09:37:36

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);
    }
}

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:

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);
    }
}
握住我的手 2024-09-01 09:37:36

只要您在函数外部声明 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文