How to create a button from array of buttons?

Hello I am trying to create an array of buttons that I can click and then trace out the name of those buttons
This is what I have.

	  private function charList(event:ProgressEvent):void {
   	 while(socket.bytesAvailable)
		{
		 		var str:String = this.socket.readUTFBytes(this.socket.bytesAvailable);
				var numbers:String = str.split("\"").join("'");
				// post my stat values :)
				var val:Array = str.split("+|+");
				var numberValues:Array=numbers.match(/(\d+)/ig);
				if(val[0].toString().length == 0)
				{
					val[0] = "create";
				}
				Names = [val[0], val[5], val[10], val[15], val[20], val[25], val[30], val[35], val[40], val[45]];
				for(var i:int = 0; i < Names.length; i++) {
					
						
						cSel.chrNam.text = Names[i];
						cSel.buttonMode = true;
						cSel.x = 100;
						cSel.y = 100 + i * 60;
						addChild(cSel);
						var e:MouseEvent;
						cSel.addEventListener(MouseEvent.CLICK, selectCharacter);
						
						
				}
			}
								
		 
	}

how would I trace out the Names[i] value when triggering the selectCharacter function?

What is cSel? If you’re adding it in the loop, it should get created in that loop too. Something like

var cSel = new Button() // or whatever

At that point, if you want to get Names[i] out of the click handler, in selectCharacter you’d use

trace(event.currentTarget.chrNam.text)

assuming you’re first parameter in selectCharacter is named event. This gets Names[i] because this is where you stored it for the button in the loop.

thanks senocular