# Simplify the AS3 code

**URL:** <https://forum.kirupa.com/t/simplify-the-as3-code/320593>\
**Category:** flash\
**Created:** [March 28, 2011, 5:18am UTC](https://forum.kirupa.com/t/simplify-the-as3-code/320593 "2011-03-28T05:18:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pizza0502](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@pizza0502](https://forum.kirupa.com/u/pizza0502)\
**Post date:** [March 28, 2011, 5:18am UTC](https://forum.kirupa.com/t/simplify-the-as3-code/320593/1 "2011-03-28T05:18:09Z")

</div>

Hi,

i’m AS3 newbie here.  
write longer script for sometimes already and thinking is it got a way to simplify the code that i’m using.

can anyone help me simplify this?

```auto
stop();

import com.greensock.*;
import com.greensock.easing.*;

var newContent1:content_tab1 = new content_tab1();
loaderMC.addChild(newContent1);
TweenMax.from(loaderMC, 0.5, {alpha:0, ease:Expo.easeOut});

monthlyBTN.addEventListener(MouseEvent.CLICK,monthClickHandler);
monthlyBTN.buttonMode=true;

weeklyBTN.addEventListener(MouseEvent.CLICK,weekClickHandler);
weeklyBTN.buttonMode=true;

grandBTN.addEventListener(MouseEvent.CLICK,grandClickHandler);
grandBTN.buttonMode=true;

function monthClickHandler(e : Event):void {
    var newContent1:content_tab1 = new content_tab1();
    loaderMC.addChild(newContent1);
    TweenMax.from(loaderMC, 0.5, {alpha:1, ease:Expo.easeOut});
}

function weekClickHandler(e : Event):void {
    var newContent2:content_tab2 = new content_tab2();
    loaderMC.addChild(newContent2);
}

function grandClickHandler(e : Event):void {
    var newContent3:content_tab3 = new content_tab3();
    loaderMC.addChild(newContent3);
}

addEventListener(Event.ENTER_FRAME,disableClick);
function disableClick(event:Event) {
    if (loaderMC.addChild(newContent1)) {
        monthlyBTN.enabled=false;
        weeklyBTN.enabled=true;
        grandBTN.enabled=true;
    }
    if (loaderMC.addChild(newContent2)) {
        monthlyBTN.enabled=true;
        weeklyBTN.enabled=false;
        grandBTN.enabled=true;
    }
    if (loaderMC.addChild(newContent3)) {
        monthlyBTN.enabled=true;
        weeklyBTN.enabled=true;
        grandBTN.enabled=false;
    }
}

```
