# Multiple if statements. code simplification

**URL:** <https://forum.kirupa.com/t/multiple-if-statements-code-simplification/309621>\
**Category:** Uncategorized\
**Created:** [May 19, 2010, 11:17pm UTC](https://forum.kirupa.com/t/multiple-if-statements-code-simplification/309621 "2010-05-19T23:17:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyPintas](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@JohnnyPintas](https://forum.kirupa.com/u/JohnnyPintas)\
**Post date:** [May 19, 2010, 11:17pm UTC](https://forum.kirupa.com/t/multiple-if-statements-code-simplification/309621/1 "2010-05-19T23:17:40Z")

</div>

hi all

I consider myself beying at begginer where actionscript comes to play, but i´m almost sure the following code could be simplified with a for loop or something similar. But i´ve tried and failed with no luck 😕

What the code does is check all buttons (hex1, hex2 and so on) if they are “clicked” (if they are at frame 25). when yes, play it.  
As it is the code does what is suposed to but i have 15 buttons so its a lot of code…

I have ommited some code within the onRelease that also does what its suposed to (show a particular image)

thanks in advance

```auto
this.onRelease = function() {
        
     if (_root.hex.hex1._currentframe == 25) {
         _root.hex.hex1.play();
     }
        
     if (_root.hex.hex2._currentframe == 25) {
         _root.hex.hex2.play();
    }
};

```

this is my attempt 😛

```auto
this.onRelease = function() {

     for (i=1;i<15;i++){
        
        if (_root.hex.hex+i._currentframe == 25) {
            _root.hex.hex+i.play();
        }
    }
};

```
