# Trying to attach functions to as created buttons

**URL:** <https://forum.kirupa.com/t/trying-to-attach-functions-to-as-created-buttons/281916>\
**Category:** Uncategorized\
**Created:** [February 15, 2009, 6:22am UTC](https://forum.kirupa.com/t/trying-to-attach-functions-to-as-created-buttons/281916 "2009-02-15T06:22:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cF516](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cF516](https://forum.kirupa.com/u/cF516)\
**Post date:** [February 15, 2009, 6:22am UTC](https://forum.kirupa.com/t/trying-to-attach-functions-to-as-created-buttons/281916/1 "2009-02-15T06:22:33Z")

</div>

hey everyone  
im trying to create a series of buttons that will take the user to a link, each link different (obv.). i dont know how many buttons im going to have because im taking in an xml file and from there determining the number of buttons ill need but i need the buttons to go to their own sites. i cant get the buttons to remember where they have to go, they just get stuck on the last 1 through the loop.

```auto
for (var i=0; i<linkCounter; i++) {
		var newPictureButton:pictureButton = new pictureButton();
		this.addChild(newPictureButton);

		newPictureButton.x=Math.random()*100;
		newPictureButton.y=Math.random()*50;
		newPictureButton.mcText.text=i+1;
		newPictureButton.name="newPictureButton"+i;
		newPictureButton.value = i;
		
		trace(newPictureButton.value = i);

		buttons*=newPictureButton;
				
		this.buttons*.link.addEventListener(MouseEvent.CLICK, function(e:Event) {clickedButton(buttons*);});
	}
	

function clickedButton(number) {
			trace(linkArray[number]);
			var request:URLRequest=new URLRequest('http://'+linkArray[number]);
			navigateToURL(request);
		}

```

any ideas?  
thanks
