# Code optimization help

**URL:** <https://forum.kirupa.com/t/code-optimization-help/248899>\
**Category:** Uncategorized\
**Created:** [January 13, 2008, 1:50am UTC](https://forum.kirupa.com/t/code-optimization-help/248899 "2008-01-13T01:50:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdawg](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kdawg](https://forum.kirupa.com/u/kdawg)\
**Post date:** [January 13, 2008, 1:50am UTC](https://forum.kirupa.com/t/code-optimization-help/248899/1 "2008-01-13T01:50:00Z")

</div>

I’m trying to condense some of this script. I’ve come a long way but I think it could be better. Is there a way I could condense this anymore?

```auto

//
buttonArray = [];
buttonArray[0] = [designButton, function () {
    gotoAndStop ("homedesign");
    section.text = "Home Design";
    setMenu (0);
}];
buttonArray[1] = [paintingButton, function () {
    gotoAndStop ("about");
    section.text = "About";
    setMenu (1);
}];
buttonArray[2] = [about, function () {
    gotoAndStop ("about");
    section.text = "About";
    setMenu (2);
}];
buttonArray[3] = [commercial, function () {
    gotoAndStop ("commercial");
    section.text = "Commercial";
    setMenu (3);
}];
buttonArray[4] = [interior, function () {
    gotoAndStop ("interior");
    section.text = "Interior";
    setMenu (4);
}];
buttonArray[5] = [exterior, function () {
    gotoAndStop ("exterior");
    section.text = "Exterior";
    setMenu (5);
}];
buttonArray[6] = [contact, function () {
    gotoAndStop ("contact");
    section.text = "Contact";
    setMenu (6);
}];

//
function setMenu (n) {
    for (var i:Number = 0; i < buttonArray.length; i++) {
        if (i != n) {
            buttonArray*[0].gotoAndStop ("up");
            buttonArray*[0].func = buttonArray*[1];
            buttonArray*[0].onRollOver = function () {
                this.gotoAndStop ("over");
            };
            buttonArray*[0].onRollOut = function () {
                this.gotoAndStop ("up");
            };
            buttonArray*[0].onPress = function () {
                this.onEnterFrame = this.func;
            };
            buttonArray*[0].onRelease = function () {
                delete this.onEnterFrame;
                delete this.onRollOver;
                delete this.onRollOut;
            };
        }
        buttonArray[n][0].gotoAndStop ("active");
    }

}

setMenu (2);

```
