# Four successive actions from one button

**URL:** <https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760>\
**Category:** flash\
**Created:** [July 12, 2008, 12:58am UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760 "2008-07-12T00:58:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 12:58am UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/1 "2008-07-12T00:58:43Z")

</div>

I am attempting to fire successive actions from the same button by setting different variables throughout the process like so…

(using Fuse to animate)

var spotOne:Boolean = true;  
var spotTwo:Boolean = false;  
var spotThree:Boolean = false;  
var spotFour:Boolean = false;

## btn.onRelease = function() { if (spotOne = true) { ball.slideTo(450, 100, 1); spotOne = false; spotTwo = true; } else if (spotTwo = true) { ball.slideTo(450, 150, .5); spotTwo = false; spotThree = true; } else if (spotThree = true) { ball.slideTo(100, 150, 1); spotThree = false; spotFour = true; } else { ball.slideTo(100, 100, 1); spotFour = false; spotOne = true; } };

This isn’t working for me. Can anyone tell me what I’m doing wrong? TIA.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 12, 2008, 1:20am UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/2 "2008-07-12T01:20:23Z")

</div>

Wrong: if (spotOne = true)  
Right: if (spotOne **==** true)  
Better: if (spotOne)

---

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 3:05pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/3 "2008-07-12T15:05:45Z")

</div>

> [@Chuckanucka;2357437](#):
>
> a switch statement might be a better option here

I had that thought but I’m not so familiar. Can you show me? TIA.

---

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 3:07pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/4 "2008-07-12T15:07:10Z")

</div>

[quote=glosrfc;2357260]Wrong: if (spotOne = true)  
Right: if (spotOne **==** true)  
Better: if (spotOne)[/quote]

Thanks glosrfc

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 12, 2008, 3:14pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/5 "2008-07-12T15:14:33Z")

</div>

There’s an example in the Flash help files…or do a search in Google for “actionscript switch” for the same example.  
There’s a simpler explaination here too [http://www.kirupa.com/developer/actionscript/switchcase.htm](http://www.kirupa.com/developer/actionscript/switchcase.htm)

---

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 6:10pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/6 "2008-07-12T18:10:59Z")

</div>

> [@glosrfc;2357449](#):
>
> There’s an example in the Flash help files…or do a search in Google for “actionscript switch” for the same example.[URL=“[kirupa.com - Flash MX: Switch / Case](http://www.kirupa.com/developer/actionscript/switchcase.htm)”]

Thanks again glosrfc. I do understand the ways of the switch in general. I’m just not sure how to execute it in the context of this function.

Here’s my somewhat incomplete stab at it. Any help is greatly appreciated.

var spotOne:Boolean = true;  
var spotTwo:Boolean = false;  
var spotThree:Boolean = false;  
var spotFour:Boolean = false;

btn.onRelease = function() {  
var location:Number = ?

switch(location) {  
case spotOne:  
ball.slideTo(450, 100, 1);  
spotOne = false;  
spotTwo = true;  
break;  
case spotTwo:  
ball.slideTo(450, 150, .5);  
spotTwo = false;  
spotThree = true;  
break;  
case spotThree:  
ball.slideTo(100, 150, 1);  
spotThree = false;  
spotFour = true;  
break;  
case spotFour:  
ball.slideTo(100, 100, 1);  
spotFour = false;  
spotOne = true;  
break;  
}

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 12, 2008, 6:59pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/7 "2008-07-12T18:59:07Z")

</div>

You won’t have a lot of luck using boolean values in a long case/switch statement because, by their nature, they only return two possibilities - true or false - and things can get messy quickly. Try this:

```auto
var button_var = 1;
btn.onRelease = function() {
	switch (button_var) {
	case 1 :
		trace("Current button value = " + button_var);
		button_var = 2;
		trace("New button value = " + button_var);
		// actions here
		break;
	case 2 :
		trace("Current button value = " + button_var);
		button_var = 3;
		trace("New button value = " + button_var);
		// actions here
		break;
	case 3 :
		trace("Current button value = " + button_var);
		button_var = 4;
		trace("New button value = " + button_var);
		// actions here
		break;
	case 4 :
		trace("Current button value = " + button_var);
		button_var = 1;
		trace("New button value = " + button_var);
		// actions here
		break;
	}
};

```

---

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 8:25pm UTC](https://forum.kirupa.com/t/four-successive-actions-from-one-button/265760/8 "2008-07-12T20:25:48Z")

</div>

Excellent! Thank you so much.
