# Variables and buttons?

**URL:** <https://forum.kirupa.com/t/variables-and-buttons/42336>\
**Category:** Uncategorized\
**Created:** [February 8, 2004, 12:54am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336 "2004-02-08T00:54:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bubba1](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bubba1](https://forum.kirupa.com/u/bubba1)\
**Post date:** [February 8, 2004, 12:54am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/1 "2004-02-08T00:54:24Z")

</div>

Hi,  
I have a movie clip button that has 3 states:  
up, over, out, and press.  
the action script inside the movie clip button looks like this:

stop();  
onRollOver = function () {  
this.gotoAndstop("\_over");  
};  
onRollOut = function () {  
this.gotoAndstop("\_out");  
};  
onPress = function () {  
this.gotAndstop("\_press");  
};

on the stage, I have several instances of this button mc.  
when the button is clicked, it loads an external file into a container on the stage.

the action script looks like this:

button\_1.onRelease = function() {  
\_root.holder1.loadMovie(“image\_1.swf”);  
\_root.button\_1.enabled = false;  
this.useHandCurser = false;  
\_root.button\_2.enabled = true;  
\_root.button\_2.gotoAndStop("\_up");  
\_root.button\_3.enabled = true;  
\_root.button\_3.gotoAndStop("\_up");  
};

button\_2.onRelease = function() {  
\_root.holder1.loadMovie(“image\_2.swf”);  
\_root.button\_2.enabled = false;  
this.useHandCurser = false;  
\_root.button\_1.enabled = true;  
\_root.button\_1.gotoAndStop("\_up");  
\_root.button\_3.enabled = true;  
\_root.button\_3.gotoAndStop("\_up");  
};

button\_3.onRelease = function() {  
\_root.holder1.loadMovie(“image\_3.swf”);  
\_root.button\_3.enabled = false;  
this.useHandCurser = false;  
\_root.button\_1.enabled = true;  
\_root.button\_1.gotoAndStop("\_up");  
\_root.button\_2.enabled = true;  
\_root.button\_2.gotoAndStop("\_up")  
};

and so on.

Now, I have 12 buttons for each section. Is there a better way to do this with variables?  
If you can help me I’d really appreciate it.

thank you

---

<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:** [February 8, 2004, 1:17am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/2 "2004-02-08T01:17:42Z")

</div>

This should work. Remove all the previous code.

```auto
for (var i = 1; i<=3; ++i) {
	this["button_"+i].i = i;
	this["button_"+i].stop();
	this["button_"+i].onRollOver = function() {
		this.gotoAndStop("_over");
	};
	this["button_"+i].onRollOut = function() {
		this.gotoAndStop("_out");
	};
	this["button_"+i].onPress = function() {
		this.gotoAndStop("_press");
	};
	this["button_"+i].onRelease = function() {
		this.enabled = false;
		this.useHandCursor = false;
		this._parent.holder1.loadMovie("image_"+this.i+".swf");
		for (var i = 1; i<=3; ++i) {
			if (this._parent["button_"+i]._name != this._name) {
				this._parent["button_"+i].enabled = true;
				this._parent["button_"+i].useHandCursor = true;
				this._parent["button_"+i].gotoAndStop("_up");
			}
		}
	};
}

```

---

<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:** [February 8, 2004, 1:42am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/3 "2004-02-08T01:42:33Z")

</div>

claudio,  
thanks for your help. It isn’t working.  
I have posted a sample file, perhaps you could take a look at it?

Thank you so much.

---

<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:** [February 8, 2004, 1:46am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/4 "2004-02-08T01:46:01Z")

</div>

Its not working because you didnt use the exactly code i posted. There were some typos. Paste the exactly code I gave you on my previous post.

---

<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:** [February 8, 2004, 1:55am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/5 "2004-02-08T01:55:14Z")

</div>

Ahhh,  
You rock! Thank you so much!

---

<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:** [February 8, 2004, 2:02am UTC](https://forum.kirupa.com/t/variables-and-buttons/42336/6 "2004-02-08T02:02:29Z")

</div>

Welcome =)
