# Help: Optimizing script using for

**URL:** https://forum.kirupa.com/t/help-optimizing-script-using-for/306592
**Category:** flash
**Created:** [March 18, 2010, 2:35am UTC](https://forum.kirupa.com/t/help-optimizing-script-using-for/306592 "2010-03-18T02:35:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zeembry](https://avatars.discourse-cdn.com/v4/letter/z/c57346/32.png) [@zeembry](https://forum.kirupa.com/u/zeembry)
#### Post date: [March 18, 2010, 2:35am UTC](https://forum.kirupa.com/t/help-optimizing-script-using-for/306592/1 "2010-03-18T02:35:41Z")

</div>

Dear All,

i’m trying to optimizing the script below, but i have problem. Please kindly help me to solve this problem.

Thanks in advanced…

```auto
/*

su=0;

onEnterFrame=function()
{
    if( su == 1 ) trace(1);
    if( su == 2 ) trace(2);
    if( su == 3 ) trace(3);
    if( su == 4 ) trace(4);
    if( su == 5 ) trace(5);
}

su1_btn.onRelease = function(){ su=1 };
su2_btn.onRelease = function(){ su=2 };
su3_btn.onRelease = function(){ su=3 };
su4_btn.onRelease = function(){ su=4 };
su5_btn.onRelease = function(){ su=5 };

*/

// OPTIMIZING THE SCRIPT ABOVE

su=0;

onEnterFrame=function() // ITS WORK !
{
    for(i=1;i<=5;i++)
    {
        if( su == i ) trace(i);
    }
}

for(j=1;j<=5;j++) // ITS NOT WORK, WHY ?
{
    this["su"+String(j)+"_btn"].onRelease = function(){ su=j }; 
}

```
