# resetting vars with button actions

**URL:** <https://forum.kirupa.com/t/resetting-vars-with-button-actions/635006>\
**Category:** Uncategorized\
**Created:** [July 25, 2016, 3:06pm UTC](https://forum.kirupa.com/t/resetting-vars-with-button-actions/635006 "2016-07-25T15:06:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxhunter](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@maxhunter](https://forum.kirupa.com/u/maxhunter)\
**Post date:** [July 25, 2016, 3:06pm UTC](https://forum.kirupa.com/t/resetting-vars-with-button-actions/635006/1 "2016-07-25T15:06:40Z")

</div>

I have three MCs and three buttons. The MCs have four frames each. I want the mouse overs to make each clip advance one frame to 2 and stay. If they click, I want it to go to frame 3. If they mouse out and then mouse over again, I want it to stay on frame 3. I wanted to use the following code to advance one frame only if it was the first mouse over. It doesn’t work.

This is the code for one button…

var correct = 0;  
var wronga =0;  
var checka =0;  
var wrongb =0;  
var checkb =0;

correct\_btn1.addEventListener(MouseEvent.MOUSE\_OVER, pop1);

function pop1(event: MouseEvent): void {  
correct ++;  
if (correct ==1){  
correct\_mc1.nextFrame();  
}  
}  
correct\_btn1.addEventListener(MouseEvent.MOUSE\_DOWN, correct1);

function correct1(event: MouseEvent): void {  
correct = 1;  
if (correct ==1){  
correct\_mc1.nextFrame();  
wrong\_mc1.gotoAndStop(1);  
wrong\_mc2.gotoAndStop(1);  
}  
}  
correct\_btn1.addEventListener(MouseEvent.MOUSE\_OUT, out1);

function out1(event: MouseEvent): void {  
correct = 0;  
checka = 0;  
wronga = 0;  
checkb = 0;  
wrongb = 0;  
}

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![maxhunter](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@maxhunter](https://forum.kirupa.com/u/maxhunter)\
**Post date:** [July 25, 2016, 3:31pm UTC](https://forum.kirupa.com/t/resetting-vars-with-button-actions/635006/2 "2016-07-25T15:31:30Z")

</div>

By the way, the “correct = 1;  
if (correct ==1)” part is fixed.

Put more simply,

var starts at 0  
mouse over sets it to 1 (++)  
mouse out sets it back to 0 (= 0)  
2nd mouse over sees that the var is 0, sets it back to 1
