# Need help on using If condition to shorten the long code in AS3.

**URL:** <https://forum.kirupa.com/t/need-help-on-using-if-condition-to-shorten-the-long-code-in-as3/634656>\
**Category:** flash\
**Created:** [May 21, 2016, 1:14pm UTC](https://forum.kirupa.com/t/need-help-on-using-if-condition-to-shorten-the-long-code-in-as3/634656 "2016-05-21T13:14:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FLearner](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@FLearner](https://forum.kirupa.com/u/FLearner)\
**Post date:** [May 21, 2016, 1:14pm UTC](https://forum.kirupa.com/t/need-help-on-using-if-condition-to-shorten-the-long-code-in-as3/634656/1 "2016-05-21T13:14:39Z")

</div>

Hi, I have the following long and repetitive AS3 code just for 3 buttons and I need to add more buttons. Since it is not the right way, I seek help from experts to help me in using If condition to shorten the code.

stop();

import com.greensock._;  
import com.greensock.easing._;

P01.addEventListener(MouseEvent.CLICK, P01btnClick);  
P02.addEventListener(MouseEvent.CLICK, P02btnClick);  
P03.addEventListener(MouseEvent.CLICK, P03btnClick);

function P01btnClick(event:MouseEvent):void {  
TweenLite.to(Page01, 1, {x:0, y:0, delay:0, ease:Circ.easeOut});

TweenLite.to(Page00, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page02, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page03, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
}

function P02btnClick(event:MouseEvent):void {  
TweenLite.to(Page02, 1, {x:0, y:0, delay:0, ease:Circ.easeOut});

TweenLite.to(Page00, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page01, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page03, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
}

function P03btnClick(event:MouseEvent):void {  
TweenLite.to(Page03, 1, {x:0, y:0, delay:0, ease:Circ.easeOut});

TweenLite.to(Page00, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page01, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
TweenLite.to(Page02, 1, {x:0, y:800, delay:0, ease:Circ.easeOut});  
}
