Write AS, to attached MC

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”);

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 :confused: