[MX] Array and For Loop Code

Hello,

Is there any reason why this code wouldn’t work:


stop();

var mediaAry = new Array("audio","downloads","photogallery","video");

for (i=1; i<=mediaAry.length; i++) {
	this["btn" + i].index = i;
	this["btn" + i].onRelease = function() {
		gotoAndStop("blank");
		btnMCTL.gotoAndStop("blank");
		imagesTL.gotoAndStop(mediaAry[this.index - 1]);
	}
};

FYI - btnMCTL is a timeline (_global.btnMCTL = this;) and imagesTL is another timeline (_global.imagesTL = this;) and have both been tested and are working correctly.

I also have 4 buttons named - btn1, btn2, btn3, and btn4 on the timeline where this frame script exists.

The line of code in question is this:


imagesTL.gotoAndStop(mediaAry[this.index - 1]);

When I replace it with a number like this:


imagesTL.gotoAndStop(mediaAry[0]);

It works, otherwise, it won’t work.

Thanks

:rd:


stop();

var mediaAry = new Array("audio","downloads","photogallery","video");

for (i=1; i<=mediaAry.length; i++) {
	this["btn" + i].index = i;
	this["btn" + i].onRelease = function() {
		gotoAndStop("blank");
		btnMCTL.gotoAndStop("blank");
		imagesTL.gotoAndStop(mediaAry[**this["btn"+i].index** - 1]);
	}
};

That should do it.