# Switch/Case - driving me mad! Help!

**URL:** <https://forum.kirupa.com/t/switch-case-driving-me-mad-help/64584>\
**Category:** flash\
**Created:** [September 17, 2004, 5:09pm UTC](https://forum.kirupa.com/t/switch-case-driving-me-mad-help/64584 "2004-09-17T17:09:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerb\_UK](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gerb_uk/32/396_2.png) [@Gerb\_UK](https://forum.kirupa.com/u/Gerb_UK)\
**Post date:** [September 17, 2004, 5:09pm UTC](https://forum.kirupa.com/t/switch-case-driving-me-mad-help/64584/1 "2004-09-17T17:09:53Z")

</div>

Hi,

I’ve attached a .fla

Basically, I want to press a button (either button 1 or button 2). Each button press sets a variable to either 1 or 2 and then plays a movie clip. Halfway through the movie clip being played, something occurs (in this case, just a trace) depending on the value of the variable managed by the ‘switch’ command.

I’ve used switch/case script, but I cannot for the life of me work out why it’s not working!

Script on buttons:

Button 1

on (release) {  
test = 1;  
circle.gotoAndPlay(2);  
}

Button 2

on (release) {  
test = 2;  
circle.gotoAndPlay(2);  
}

Script on frame 10 of ‘circle’

switch (test) {  
case 1 :  
trace(“button one”);  
break;  
case 2 :  
trace(“button two”);  
break;  
default :  
trace(“neither”);  
}

Whateverm button I press returns ‘neither’ in the trace?

Help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 17, 2004, 5:29pm UTC](https://forum.kirupa.com/t/switch-case-driving-me-mad-help/64584/2 "2004-09-17T17:29:02Z")

</div>

> [@Gerb (UK)](#):
>
> Hi,
> 
> I’ve attached a .fla
> 
> Basically, I want to press a button (either button 1 or button 2). Each button press sets a variable to either 1 or 2 and then plays a movie clip. Halfway through the movie clip being played, something occurs (in this case, just a trace) depending on the value of the variable managed by the ‘switch’ command.
> 
> I’ve used switch/case script, but I cannot for the life of me work out why it’s not working!
> 
> Script on buttons:
> 
> Button 1
> 
> on (release) {  
> test = 1;  
> circle.gotoAndPlay(2);  
> }
> 
> Button 2
> 
> on (release) {  
> test = 2;  
> circle.gotoAndPlay(2);  
> }
> 
> Script on frame 10 of ‘circle’
> 
> switch (test) {  
> case 1 :  
> trace(“button one”);  
> break;  
> case 2 :  
> trace(“button two”);  
> break;  
> default :  
> trace(“neither”);  
> }
> 
> Whateverm button I press returns ‘neither’ in the trace?
> 
> Help!

change the button codes to  
on (release) {  
circle.test = 2;  
circle.gotoAndPlay(2);  
}  
on (release) {  
circle.test = 1;  
circle.gotoAndPlay(2);  
}
