# Callback button function in a "for" loop

**URL:** <https://forum.kirupa.com/t/callback-button-function-in-a-for-loop/84696>\
**Category:** Uncategorized\
**Created:** [March 29, 2005, 8:49pm UTC](https://forum.kirupa.com/t/callback-button-function-in-a-for-loop/84696 "2005-03-29T20:49:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fRedline](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fredline/32/1219_2.png) [@fRedline](https://forum.kirupa.com/u/fRedline)\
**Post date:** [March 29, 2005, 8:49pm UTC](https://forum.kirupa.com/t/callback-button-function-in-a-for-loop/84696/1 "2005-03-29T20:49:01Z")

</div>

The type of “for loop” in question:

for (i=1; i\<5; i++) {  
theClip=“clip”+i;  
eval(theClip).onPress = function() {  
found(i); // passes the i variable to a hypothetical “found” function  
}  
}

“theClip” evaluates correctly, i.e. clip1, clip2, clip3, clip4.

The i inside the callback function is useless though. Every clip’s onPress function will pass 4 (the last loop #) to the “found” function.

I must be totally missing some basic restriction on callbacks. Any help for a quick learner? Thank you!
