# Assigning functions via a loop

**URL:** <https://forum.kirupa.com/t/assigning-functions-via-a-loop/113725>\
**Category:** Uncategorized\
**Created:** [June 21, 2004, 12:39pm UTC](https://forum.kirupa.com/t/assigning-functions-via-a-loop/113725 "2004-06-21T12:39:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rossbruniges](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rossbruniges/32/584_2.png) [@rossbruniges](https://forum.kirupa.com/u/rossbruniges)\
**Post date:** [June 21, 2004, 12:39pm UTC](https://forum.kirupa.com/t/assigning-functions-via-a-loop/113725/1 "2004-06-21T12:39:35Z")

</div>

I am working on a page where three differnt buttons effect one movie clips properties, the one movie clip will go to its rollover state when any of the buttons are on rollover, hmm, that sounds about right]

i have assigned functions within a loop and the rollovers, rollouts and instance in the loop have been defined for all but the movieClips dont go to the right place…

the code i have used is this…

```auto
 for (var i:Number = 1; i < 4; i++) {
// attaching ALL rollovers to effect the interactive button
this["invis"+i+"_btn"].onRollOver = this["chart"+i+"_btn"].onRollOver = this["inter"+i+"_mc"].onRollOver = function() {
buttonName = this._name;
buttonNumber = Number(buttonName.substr(5, 1));
trace ("rollover");
trace (buttonNumber);
this["inter"+buttonNumber+"_mc"].gotoAndStop("on");
}
this["invis"+i+"_btn"].onRollOut = this["chart"+i+"_btn"].onRollOut = this["inter"+i+"_mc"].onRollOut = function() {
trace ("rollout");
buttonName = this._name;
buttonNumber = Number(buttonName.substr(5, 1));
this["inter"+buttonNumber+"_mc"].gotoAndStop("normal");
}
} 

```

as i have said…all the traces show up correct but not the gotoAndStop on the movieClip (inter+i+_mc_)'s

any ideas??
