# Mild diffifulty - For loops, and 6 buttons w/ event listeners

**URL:** <https://forum.kirupa.com/t/mild-diffifulty-for-loops-and-6-buttons-w-event-listeners/314784>\
**Category:** Uncategorized\
**Created:** [October 8, 2010, 5:37pm UTC](https://forum.kirupa.com/t/mild-diffifulty-for-loops-and-6-buttons-w-event-listeners/314784 "2010-10-08T17:37:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![toussant](https://avatars.discourse-cdn.com/v4/letter/t/a5b964/32.png) [@toussant](https://forum.kirupa.com/u/toussant)\
**Post date:** [October 8, 2010, 5:37pm UTC](https://forum.kirupa.com/t/mild-diffifulty-for-loops-and-6-buttons-w-event-listeners/314784/1 "2010-10-08T17:37:32Z")

</div>

```auto

[COLOR="Red"]
var Labelz:Array=["Label Alpha","Label Alpha2","Alpha3","Label4 ","Label Alph5a","Alpha6"];
var Linkz:Array=["Contact","Report","Link","Broke","Suggest","Link"];
[/COLOR]
////////////////// text format and font embed. 
var font:Font1=new Font1();
var txt_fmt:TextFormat=new TextFormat();
txt_fmt.font=font.fontName;
txt_fmt.size=21;

////////////////// For loop, creates buttons and adds event listeners. 
[COLOR="red"]for (var i:Number = 0; i < 6; i++) {[/COLOR]

[COLOR="red"]	var txt:TextField = new TextField();
	txt.name="txt"+i;
	addChild(txt); [/COLOR]
	txt.x=179;
	txt.y=209+i*40;
	txt.defaultTextFormat=txt_fmt;
  [COLOR="Red"] txt.appendText( Labelz* );[/COLOR]
	[COLOR="red"]txt.addEventListener(MouseEvent.MOUSE_DOWN, doThis);
	
	function doThis(evt:MouseEvent):void {
		trace(Linkz*);
	}[/COLOR]

[COLOR="red"]}[/COLOR]

```

Hello friends, I want each button I create to load its own value from the Array Linkz when the user clicks on it.

but I cant seem to get ‘i’ to represent its corresponding value. its always 6…

what am I doing wrong?

\*eventually the linkz array will represent a movieclip that I want to load from the library, or from an external folder :0) \*
