# Write AS, to attached MC

**URL:** https://forum.kirupa.com/t/write-as-to-attached-mc/210049
**Category:** flash
**Created:** [December 14, 2006, 2:08pm UTC](https://forum.kirupa.com/t/write-as-to-attached-mc/210049 "2006-12-14T14:08:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Esseti](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Esseti](https://forum.kirupa.com/u/Esseti)
#### Post date: [December 14, 2006, 2:08pm UTC](https://forum.kirupa.com/t/write-as-to-attached-mc/210049/1 "2006-12-14T14:08:38Z")

</div>

Hi,

Im trying to write a function that will build a menu based upon the vars that I passed it to. This is a simpler version on the code. (The library has a MC/Btn symbol with the linkage “btn”);

```auto
function bulidMenu(nItems:Number) {
	var menuMCx:Number = 100;
	var menuMCy:Number = 100;
	this.createEmptyMovieClip("menuMC", this.getNextHighestDepth());
	menuMC._x = menuMCx;
	menuMC._y = menuMCy;
	for (i=0; i<nItems; i++) {
		menuMC.attachMovie("btn", "btn"+i, i);
		menuMC["btn"+i]._x = menuMC._width+10;
		menuMC["btn"+i].onRelease = function() {
			trace(i);
		}
	}
}
bulidMenu(4);

```

Why do I get an output of 4 on every clicked button, instead of 0,1,2,3 ? I tryed forwarding the " i " to the onRelease = function(i) {} and then in it declaring a new var and assigning it the passed " i ", but that doesn’t work either 😕
