# Multiple Buttons - One Function - Different Addchilds

**URL:** <https://forum.kirupa.com/t/multiple-buttons-one-function-different-addchilds/324674>\
**Category:** flash\
**Created:** [September 2, 2011, 2:40pm UTC](https://forum.kirupa.com/t/multiple-buttons-one-function-different-addchilds/324674 "2011-09-02T14:40:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shakaBoy](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@shakaBoy](https://forum.kirupa.com/u/shakaBoy)\
**Post date:** [September 2, 2011, 2:40pm UTC](https://forum.kirupa.com/t/multiple-buttons-one-function-different-addchilds/324674/1 "2011-09-02T14:40:30Z")

</div>

Hello everyone,

Here’s my dilemma - I have two buttons (home and contact) (and two pages) and I want to send them to the same function. In the function I have a pagecontainer.addChild() but I want the function to know which button I clicked and add the correct page. I have no errors in the output window but the contact page keeps tweening in even if I click the home button. Thanks for any help in advance.

the code I have:

var home:home\_page = new home\_page;  
var contact:contact\_page = new contact\_page;

pageContainer\_mc.addChild(home);  
var pageIntroTween:Tween = new Tween(pageContainer\_mc, “y”, Elastic.easeOut, 500, 100, 2, true);

var BtnArray:Array =[“home\_btn”, “contact\_btn”];

for each (var \_btn in BtnArray) {  
addEventListener(MouseEvent.CLICK, onBtnClick);  
}

function onBtnClick (event:MouseEvent):void  
{  
var Outro:Tween = new Tween(pageContainer\_mc, “x”, Back.easeIn, pageContainer\_mc.x, -500, 1, true);  
Outro.addEventListener(TweenEvent.MOTION\_FINISH, runTransition);

function runTransition (event:TweenEvent):void  
{  
pageContainer\_mc.removeChildAt(1);

if(\_btn in BtnArray == “home\_btn”){  
pageContainer\_mc.addChild(home);  
}else{  
pageContainer\_mc.addChild(contact);  
}  
var Intro:Tween = new Tween(pageContainer\_mc, “x”, Strong.easeOut, pageContainer\_mc.x=500, 250, 1, true);  
}  
}
