# Why doesn't this For Loop work?

**URL:** <https://forum.kirupa.com/t/why-doesnt-this-for-loop-work/166936>\
**Category:** flash\
**Created:** [October 24, 2005, 5:47am UTC](https://forum.kirupa.com/t/why-doesnt-this-for-loop-work/166936 "2005-10-24T05:47:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake74](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jake74](https://forum.kirupa.com/u/jake74)\
**Post date:** [October 24, 2005, 5:47am UTC](https://forum.kirupa.com/t/why-doesnt-this-for-loop-work/166936/1 "2005-10-24T05:47:21Z")

</div>

This works fine:

```auto

_root.artist_mc.cd_btn0.onRelease = function(){
	_root.discDetail_mc._visible = true;
	_root.discDetail_mc.cdTitle_txt.text = thisItem.menu_item_btn.cdTitle[0];
}//Ends this onRelease function
 
_root.artist_mc.cd_btn1.onRelease = function(){
	_root.discDetail_mc._visible = true;
	_root.discDetail_mc.cdTitle_txt.text = thisItem.menu_item_btn.cdTitle[1];
}//Ends this onRelease function
 
_root.artist_mc.cd_btn2.onRelease = function(){
	_root.discDetail_mc._visible = true;
	_root.discDetail_mc.cdTitle_txt.text = thisItem.menu_item_btn.cdTitle[2];
}//Ends this onRelease function
 

```

But this just gives me “undefined”. If I set the dynamic text to = n, I always get “3” (the length of the array).

```auto

for(n=0;n<thisItem.menu_item_btn.cdTitle.length;n++){
_root.artist_mc["cd_btn"+n].onRelease = function(){
		_root.discDetail_mc._visible = true;
		_root.discDetail_mc.cdTitle_txt.text = thisItem.menu_item_btn[cdTitle[n]];
	}
}

```

So why doesn’t the for loop work?
