# Dynamic Button Functions

**URL:** <https://forum.kirupa.com/t/dynamic-button-functions/172918>\
**Category:** flash\
**Created:** [December 19, 2005, 5:01pm UTC](https://forum.kirupa.com/t/dynamic-button-functions/172918 "2005-12-19T17:01:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stibos](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stibos](https://forum.kirupa.com/u/stibos)\
**Post date:** [December 19, 2005, 5:01pm UTC](https://forum.kirupa.com/t/dynamic-button-functions/172918/1 "2005-12-19T17:01:24Z")

</div>

Hi, I’m trying to dynamically set the text for captions that get triggered on a button rollover.

Currently I have, thanks to the kirupa tutorial…

```auto

b1.onRollOver = function() { 
	captionFN(true, "text for the caption", this); 
	this.onRollOut = function() { 
	 captionFN(false); 
	}; 
};

```

but I have about fifty buttons, i.e b1, b2 ,b3 ,… . b50 and the caption text is read from an xml file so I could just copy and paste that 50 times but would much prefer to be able to have it a small for loop.

So what I would thought might work for my problem was:

```auto

for (var i:Number=0; i < 50; i++) {
	root["b" + i].onRollOver = function() {
		captionFN(true, arrPlotText*, this); 
		this.onRollOut = function() { 
			 captionFN(false); 
		 }; 
	};
}

```

where the buttons are on \_root and the array -\> arrPlotText is already filled with the text needed, but it doesnt work.

cheers to anyone who can help.  
stibos
