# Why can't add btn.onRelease in a loop?

**URL:** <https://forum.kirupa.com/t/why-cant-add-btn-onrelease-in-a-loop/199251>\
**Category:** Uncategorized\
**Created:** [August 31, 2006, 11:09pm UTC](https://forum.kirupa.com/t/why-cant-add-btn-onrelease-in-a-loop/199251 "2006-08-31T23:09:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skyp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/skyp/32/2681_2.png) [@skyp](https://forum.kirupa.com/u/skyp)\
**Post date:** [August 31, 2006, 11:09pm UTC](https://forum.kirupa.com/t/why-cant-add-btn-onrelease-in-a-loop/199251/1 "2006-08-31T23:09:04Z")

</div>

Hello, experts

I’m tring to add a onRelease event into every button I have, code like

> 

```
for(var i = 1; i &lt;= totalPage; i++){
    _root['button'+i].onRelease = function(){gotoPage(i-1)};
}    

```

why its doesnt work.  
I have to do like following

> 

```
    button1.onRelease = function(){gotoPage(0)};
    button2.onRelease = function(){gotoPage(1)};
    button3.onRelease = function(){gotoPage(2)};
    button4.onRelease = function(){gotoPage(3)};
    button5.onRelease = function(){gotoPage(4)};

```

any help would be appriciated!
