views:

381

answers:

2

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);
    }
}
+1  A: 

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);
    }
}
Amarghosh
It's all inside the first frame of the actions layer. I ran the function you provided. The before continually equals 0, while the after equals 1. So right away I can tell that the value of the cCount variable is being reset. Yet, I can't solve this.
Michael Stone
The problem wasn't in the programming, it was in the actual stage. I was playing a movieClip in frame 1, where I was also declaring the cCount variable. The solution was to create some spacer frames and start playing on a different frame, other than frame 1.
Michael Stone
A: 

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.

DraStudio