# Referring confusion

**URL:** https://forum.kirupa.com/t/referring-confusion/302948
**Category:** Uncategorized
**Created:** [January 11, 2010, 4:40am UTC](https://forum.kirupa.com/t/referring-confusion/302948 "2010-01-11T04:40:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kingnimrod](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kingnimrod](https://forum.kirupa.com/u/kingnimrod)
#### Post date: [January 11, 2010, 4:40am UTC](https://forum.kirupa.com/t/referring-confusion/302948/1 "2010-01-11T04:40:31Z")

</div>

I am trying to figure out how to refer to buttons generically so I can change their color by setting a variable, and am having some difficulty figuring out how to refer to buttons (button0, button1, button2, etc) in the following code:

```auto

stop();

//tween class
#include "mc_tween2.as"

//buttons
//INSERT NAMES HERE, IN ARRAY
// **********************
var buttons:Array = new Array("HOME", "PROPOSAL", "PDF", "BUDGET", "WALLPAPERS", "CONTACT");
// **********************

//init position
var posx:Number = 0;
var posy:Number = 60;

//width bar
var tamW:Number = 150;

//id current button
var curr:Number;

var colorful = new Color("?");

//function call menu
function createButtons ():Void {
	for(var i:Number = 0; i < buttons.length; i++) {
		
		//get on the library
		this.attachMovie("button", "button"+i, i);
		var button:Object = this["button"+i];
		
		//add name
		button.nameButton.text = buttons*;
		
		//add id in button
		button.id = i;
		
		//position buttons
		button._x = posx;
		button._y = posy;
		posy += button._height + 1;
		
		//init bar
		button.bg._width = 0;
		
		//button actions
		button.onRollOver = function () {
			this.bg.tween("_width", tamW, 0.6, "easeoutexpo");
			this.nameButton.textColor = 0x000000;
		}
		button.onRollOut = button.onReleaseOutside = function () {
			if(this.id != curr) {
				this.nameButton.textColor = 0xFFFFFF;
				this.bg.tween("_width", 0, 0.6, "easeoutexpo");
			}
		}
		button.onRelease = function () {
			if(this.id != curr) {
				this._parent["button"+curr].bg.tween("_width", 0, 0.6, "easeoutexpo");
				this._parent["button"+curr].nameButton.textColor = 0xFFFFFF;
				colorful.setRGB(0xFFCC66);
				curr = this.id;
				//Example
				//buttons[this.id] == HOME or NEWS or PORTFOLIO.....
				gotoAndStop(buttons[this.id]);
				// *******************
				//YOUR ACTION HERE
				// *******************
			}
		}
	}
}

//Init
createButtons();
colorful.setRGB(0xFFCC33);

```

additionally, if someone can give me some help in how to assign a color to each button so they all change color to the new color when a button is pressed, that would be much appreciated.

Thanks!
