# AS Button question

**URL:** <https://forum.kirupa.com/t/as-button-question/184183>\
**Category:** flash\
**Created:** [April 3, 2006, 2:29am UTC](https://forum.kirupa.com/t/as-button-question/184183 "2006-04-03T02:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thats\_all\_folks](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@thats\_all\_folks](https://forum.kirupa.com/u/thats_all_folks)\
**Post date:** [April 3, 2006, 2:29am UTC](https://forum.kirupa.com/t/as-button-question/184183/1 "2006-04-03T02:29:45Z")

</div>

I was looking over this code for building buttons with as, but how do you asign an action to each of them. Like if I wanted to make one button load a movie.

i = 0;  
count = 10;  
// these vars are for the color of things…  
oCBG = 0x666666;// old color (what your bg is now)  
ncBG = 0x999999;// new color (what it will be on rollover)  
oCTx = 0x333333;// old color of text  
nCTx = 0x006699;// the new color of your text  
onEnterFrame = function () {  
if (i\<count) {  
btn = \_root.attachMovie(“button”, “button”+i, i);  
btn.\_x = 50;  
btn.\_y = (20\*i)+50;  
btn.onRollOver = function() {  
cObj = new Color(this.bg);  
cObj.setRGB(ncBG);  
format = new TextFormat();  
format.color = nCTx;  
this.btnText.setTextFormat(format);  
};btn.onRollOut = function() {  
cObj = new Color(this.bg);  
cObj.setRGB(oCBG);  
format = new TextFormat();  
format.color = oCTx;  
this.btnText.setTextFormat(format);  
};  
btn.btnText.text += " "+i;i++;  
}  
};  
stop();

Thanks for the help

Thomas

---

<div class="post-metadata">

**Author:** ![thats\_all\_folks](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@thats\_all\_folks](https://forum.kirupa.com/u/thats_all_folks)\
**Post date:** [April 3, 2006, 1:03pm UTC](https://forum.kirupa.com/t/as-button-question/184183/2 "2006-04-03T13:03:47Z")

</div>

I’ve been trying if statements, but nothing seems to work. any ideas?

---

<div class="post-metadata">

**Author:** ![Dutchy](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Dutchy](https://forum.kirupa.com/u/Dutchy)\
**Post date:** [April 3, 2006, 1:12pm UTC](https://forum.kirupa.com/t/as-button-question/184183/3 "2006-04-03T13:12:49Z")

</div>

hi,

try this:

```auto

count = 10;
// these vars are for the color of things...
oCBG = 0x666666;
// old color (what your bg is now)
ncBG = 0x999999;
// new color (what it will be on rollover)
oCTx = 0x333333;
// old color of text
nCTx = 0x006699;
// the new color of your text
for (i=0; i<count; i++) {
	btn = _root.attachMovie("button", "button"+i, i);
	btn.n = i;
	btn._x = 50;
	btn._y = (20*i)+50;
	btn.onRollOver = function() {
		cObj = new Color(this.bg);
		cObj.setRGB(ncBG);
		format = new TextFormat();
		format.color = nCTx;
		this.btnText.setTextFormat(format);
	};
	btn.onRollOut = function() {
		cObj = new Color(this.bg);
		cObj.setRGB(oCBG);
		format = new TextFormat();
		format.color = oCTx;
		this.btnText.setTextFormat(format);
	};
	btn.onPress = function() {
		//change to the color you want
		cObj = new Color(this.bg);
		cObj.setRGB(oCBG);
		format = new TextFormat();
		format.color = oCTx;
		this.btnText.setTextFormat(format);
		target.loadMovie("url/movie"+this.n+".swf");
		//or and add array with the movienames
		target.loadMovie("url/"+movieArray[this.n]);
	};
	btn.btnText.text += " "+i;
	i++;
}
stop();

```

Dutchy
