# Shortening actionscript?

**URL:** <https://forum.kirupa.com/t/shortening-actionscript/295764>\
**Category:** flash\
**Created:** [September 3, 2009, 10:45pm UTC](https://forum.kirupa.com/t/shortening-actionscript/295764 "2009-09-03T22:45:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorne17](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lorne17](https://forum.kirupa.com/u/lorne17)\
**Post date:** [September 3, 2009, 10:45pm UTC](https://forum.kirupa.com/t/shortening-actionscript/295764/1 "2009-09-03T22:45:18Z")

</div>

Hello there,

I know this is simple, but I always have a hard time shortening script. Can someone help me shorten this?

```auto
MenuBar.btn_Menu0.onRollOver = function() {
        MenuBar.Menu0.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu0.onRollOut = function() {
        MenuBar.Menu0.gotoAndPlay("Out");
        };
        
    MenuBar.btn_Menu1.onRollOver = function() {
        MenuBar.Menu1.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu1.onRollOut = function() {
        MenuBar.Menu1.gotoAndPlay("Out");
        };

    MenuBar.btn_Menu2.onRollOver = function() {
        MenuBar.Menu2.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu2.onRollOut = function() {
        MenuBar.Menu2.gotoAndPlay("Out");
        };

    MenuBar.btn_Menu3.onRollOver = function() {
        MenuBar.Menu3.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu3.onRollOut = function() {
        MenuBar.Menu3.gotoAndPlay("Out");
        };

    MenuBar.btn_Menu4.onRollOver = function() {
        MenuBar.Menu4.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu4.onRollOut = function() {
        MenuBar.Menu4.gotoAndPlay("Out");
        };

    MenuBar.btn_Menu5.onRollOver = function() {
        MenuBar.Menu5.gotoAndPlay("Over");
        };
    
    MenuBar.btn_Menu5.onRollOut = function() {
        MenuBar.Menu5.gotoAndPlay("Out");
        };

```

I tried this…but to no avail

```auto
for (var i = 0; i<6; i++) {
    MenuBar["btn_Menu"+i].onRollOver = function() {
        MenuBar["Menu"+i}.gotoAndPlay("Over");
        };
    
    MenuBar["btn_Menu"+i].onRollOut = function() {
        MenuBar["Menu"+i].gotoAndPlay("Out");
        };
    
    MenuBar["btn_Menu"+i].onRelease = function() {
        var id:Number = Number(this._name.substr(4));
        getURL(url[id]);
        if (id != 0) {
            MenuBar["Menu"+i].enabled = false;
            }
            old.enabled = true;
        if (old != MenuBar.Menu0) {
            old.gotoAndPlay("Out");
            }
            old = this;
            };
}

```

Thanks,  
Lorne
