# Dynamically assigning functions to button events results in problems

**URL:** <https://forum.kirupa.com/t/dynamically-assigning-functions-to-button-events-results-in-problems/291154>\
**Category:** flash\
**Created:** [June 25, 2009, 10:56am UTC](https://forum.kirupa.com/t/dynamically-assigning-functions-to-button-events-results-in-problems/291154 "2009-06-25T10:56:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![philistine](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@philistine](https://forum.kirupa.com/u/philistine)\
**Post date:** [June 25, 2009, 10:56am UTC](https://forum.kirupa.com/t/dynamically-assigning-functions-to-button-events-results-in-problems/291154/1 "2009-06-25T10:56:35Z")

</div>

Hi all,

I was wondering if someone might be able to assist with an issue that I am encountering with a project that I am currently working on.

I am in the process of writing a scrolling image viewer that dynamically updates from an xml file. I have written the scroll function (with a lot of help from Kirupa and other sources), and the pictures are updating beautifully, but when it comes to adding the function for the buttons I am encountering an unusual error.

Using the following code:

```auto
initButtons=function(){
 for (var i in btnArray) {  
      var btn:MovieClip = btnArray*;
  btn.thumbLoaderMC.loadMovie(thumb*);
  btn.onRelease= doClick();
 }
}

```

from [this](http://flash-creations.com/notes/actionscript_groupofbuttons.php) site results in the doClick function being called for each of the buttons in the btn array at runtime, and then not working afterwards. I have included the code if it helps.

Help me Kirupa, you’re my only hope! :vader:  
Thank you in advance

Phil
