# Button calls function once, not again...?

**URL:** <https://forum.kirupa.com/t/button-calls-function-once-not-again/323036>\
**Category:** Uncategorized\
**Created:** [June 14, 2011, 9:21pm UTC](https://forum.kirupa.com/t/button-calls-function-once-not-again/323036 "2011-06-14T21:21:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbyle](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@bbyle](https://forum.kirupa.com/u/bbyle)\
**Post date:** [June 14, 2011, 9:21pm UTC](https://forum.kirupa.com/t/button-calls-function-once-not-again/323036/1 "2011-06-14T21:21:41Z")

</div>

CS5 AS 3.0

Hey guys. I’ve only been using AS 3.0 for about 3 months and using it to build a portfolio site. No classes here, Im not there yet so please bear with.

Here is my problem: When I click on my MC(portMC) it runs a tween and calls a few tween functions to open its child MC, portMain. Inside portMain there is a close button.(MC acting as button). When I click it, all closes fine and returns to the site. But if I click mcPort to re enter that same section of the site (mcPort) my tween functions play but portMain never reopens. ??? after the first visit to portMain I cannot reenter it. ideas? Code below with comments. Sorry I know its huge just didnt want to leave anything out!

-bbyle

addEventListener(MouseEvent.CLICK,panelsHide);  
addEventListener(MouseEvent.MOUSE\_OVER,overStates) ;  
addEventListener(MouseEvent.MOUSE\_OUT,outStates);  
addEventListener(MouseEvent.CLICK,clickStates);

function clickStates(e:MouseEvent):void  
{  
if (e.target == mcPort)  
{  
e.target.gotoAndStop(“over”);  
}  
else if (e.target == mcRes)  
{  
e.target.gotoAndStop(“over”);  
}  
else if (e.target == mcWeb)  
{  
e.target.gotoAndStop(“over”);  
}  
else if (e.target == mcCon)  
{  
e.target.gotoAndStop(“over”);  
}  
}

//HIDES 3 OTHER MCs ON STAGE///////////////////////////////////////  
function panelsHide(e:MouseEvent):void  
{  
if (e.target == mcPort)  
{  
var portFadeOutConA:Tween = new Tween(mcCon,‘alpha’,null,1,.4,.4,true);  
var portFadeOutResA:Tween = new Tween(mcRes,‘alpha’,null,1,.4,.4,true);  
var portFadeOutWebA:Tween = new Tween(mcWeb,‘alpha’,null,1,.4,.4,true);  
portFadeOutConA.addEventListener(TweenEvent.MOTION _FINISH,slotOpenPort);  
}  
else if (e.target == mcRes)  
{  
var resFadeOutConA:Tween = new Tween(mcCon,‘alpha’,null,1,.4,.4,true);  
var resFadePortResA:Tween = new Tween(mcPort,‘alpha’,null,1,.4,.4,true);  
var resFadeOutWebA:Tween = new Tween(mcWeb,‘alpha’,null,1,.4,.4,true);  
resFadeOutConA.addEventListener(TweenEvent.MOTION_ FINISH,slotOpenRes);  
}  
else if (e.target == mcWeb)  
{  
var webFadeOutConA:Tween = new Tween(mcCon,‘alpha’,null,1,.4,.4,true);  
var webFadeOutResA:Tween = new Tween(mcRes,‘alpha’,null,1,.4,.4,true);  
var webFadeOutPortA:Tween = new Tween(mcPort,‘alpha’,null,1,.4,.4,true);  
webFadeOutConA.addEventListener(TweenEvent.MOTION\_ FINISH,slotOpenWeb);  
}  
else if (e.target == mcCon)  
{  
var conFadeOutPortA:Tween = new Tween(mcPort,‘alpha’,null,1,.4,.4,true);  
var conFadeOutResA:Tween = new Tween(mcRes,‘alpha’,null,1,.4,.4,true);  
var conFadeOutWebA:Tween = new Tween(mcWeb,‘alpha’,null,1,.4,.4,true);  
conFadeOutPortA.addEventListener(TweenEvent.MOTION \_FINISH,slotOpenCon);  
}  
}

//TRANSITION TWEEN///////////////////////////////////////////////  
var slotOpenPortXS:Tween;

function slotOpenPort(e:TweenEvent):void  
{  
addChild(slotWindowPortMC);  
slotWindowPortMC.visible = true;  
slotOpenPortXS = new Tween(slotWindowPortMC,‘scaleX’,null,0,.125,.2,tru e);  
slotOpenPortXS.addEventListener(TweenEvent.MOTION\_ FINISH,portDrop);  
}

//TRANSITION TWEEN///////////////////////////////////////////////  
var mcPortDrop:Tween;

function portDrop(e:TweenEvent):void  
{  
mcPortDrop = new Tween(mcPort,‘y’,Strong.easeOut,mcPort.y,openingWi ndowMC.y,.5,true);  
mcPortDrop.addEventListener(TweenEvent.MOTION\_FINI SH,portPanel);  
}

//PORTMAIN ENTERS . WORKS FINE FIRST TIME, NOT AFTER//////////////////  
function portPanel(e:TweenEvent):void  
{  
addChild(portMain);  
portMain.visible = true;  
portMain.x = 500;  
portMain.y = 300;  
portMain.gotoAndPlay(2);  
portMain.addEventListener(Event.ENTER\_FRAME,portMa inEnter);;  
}

//CHILD MCS ADDED TO DISPLAY LIST////////////////////////////  
function portMainEnter(e:Event):void  
{  
if (portMain.currentFrame == 10)  
{  
portMain.removeEventListener(Event.ENTER\_FRAME,por tMainEnter);  
portMain.buttonMode = false;  
portMain.close\_btn.buttonMode = true;

```
    portMain.bodyFormMC.visible = true;
    portMain.bodyFormMC.x = -355;
    portMain.bodyFormMC.y = -165;
    portMain.bodyFormMC.gotoAndPlay(2);
    portMain.bodyFormMC.buttonMode = true;

    portMain.boomBoxMC.visible = true;
    portMain.boomBoxMC.x = -235;
    portMain.boomBoxMC.y = -165;
    portMain.boomBoxMC.gotoAndPlay(2);
    portMain.boomBoxMC.buttonMode = true;

    portMain.laptopMC.visible = true;
    portMain.laptopMC.x = -355;
    portMain.laptopMC.y = -55;
    portMain.laptopMC.gotoAndPlay(2);
    portMain.laptopMC.buttonMode = true;

    portMain.lumbarMC.visible = true;
    portMain.lumbarMC.x = -235;
    portMain.lumbarMC.y = -55;
    portMain.lumbarMC.gotoAndPlay(2);
    portMain.lumbarMC.buttonMode = true;

    portMain.shaverMC.visible = true;
    portMain.shaverMC.x = -355;
    portMain.shaverMC.y = 55;
    portMain.shaverMC.gotoAndPlay(2);
    portMain.shaverMC.buttonMode = true;

    portMain.wandMC.visible = true;
    portMain.wandMC.x = -235;
    portMain.wandMC.y = 55;
    portMain.wandMC.gotoAndPlay(2);
    portMain.wandMC.buttonMode = true;

    portMain.handHeldMC.visible = true;
    portMain.handHeldMC.x = -355;
    portMain.handHeldMC.y = 165;
    portMain.handHeldMC.gotoAndPlay(2);
    portMain.handHeldMC.buttonMode = true;
}

```

}  
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx  
//CODE HERE TO NAVIGATE CHILD MCs//////////////////////////////////////  
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx

//CLOSE PORT MAIN//////////////////////////////////////////////////////////////  
portMain.close\_btn.addEventListener(MouseEvent.CLI CK,portClose);

var portMainExit:Tween;

function portClose(e:MouseEvent):void  
{  
portMain.bodyFormMC.visible = false;  
portMain.boomBoxMC.visible = false;  
portMain.laptopMC.visible = false;  
portMain.lumbarMC.visible = false;  
portMain.shaverMC.visible = false;  
portMain.wandMC.visible = false;  
portMain.handHeldMC.visible = false;  
portMainExit = new Tween(portMain,‘scaleY’,Strong.easeOut,1,0,.3,true );  
portMain.gotoAndStop(1);  
portMain.bodyFormMC.gotoAndStop(1);  
portMain.boomBoxMC.gotoAndStop(1);  
portMain.handHeldMC.gotoAndStop(1);  
portMain.laptopMC.gotoAndStop(1);  
portMain.lumbarMC.gotoAndStop(1);  
portMain.shaverMC.gotoAndStop(1);  
portMain.wandMC.gotoAndStop(1);  
portMainExit.addEventListener(TweenEvent.MOTION\_FI NISH,portUp);  
}

//CLOSING TWEEN//////////////////////////////////////////////////////////  
var portUpY:Tween;

function portUp(e:TweenEvent):void  
{  
portUpY = new Tween(mcPort,‘y’,Strong.easeOut,mcPort.y,smallPane lMCPort.y,.3,true);  
portUpY.addEventListener(TweenEvent.MOTION\_FINISH, slotPortClose);  
}

var slotPortCloseXS:Tween;

function slotPortClose(e:TweenEvent):void  
{  
slotPortCloseXS = new Tween(slotWindowPortMC,‘scaleX’,null,.125,0,.2,tru e);  
slotPortCloseXS.addEventListener(TweenEvent.MOTION \_FINISH,portPanelsReturn);  
}

//CLOSING TWEEN, 3 MCs RETURN TO STAGE/////////////////////////////  
var portFadeInConA:Tween;  
var portFadeInResA:Tween;  
var portFadeInWebA:Tween;

function portPanelsReturn(e:TweenEvent):void  
{  
slotWindowPortMC.visible = false;  
portFadeInConA = new Tween(mcCon,‘alpha’,null,.4,1,.4,true);  
portFadeInResA = new Tween(mcRes,‘alpha’,null,.4,1,.4,true);  
portFadeInWebA = new Tween(mcWeb,‘alpha’,null,.4,1,.4,true);  
}
