# Calling a fuction from external swf

**URL:** <https://forum.kirupa.com/t/calling-a-fuction-from-external-swf/306935>\
**Category:** Uncategorized\
**Created:** [March 24, 2010, 8:18pm UTC](https://forum.kirupa.com/t/calling-a-fuction-from-external-swf/306935 "2010-03-24T20:18:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvinatea](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@dvinatea](https://forum.kirupa.com/u/dvinatea)\
**Post date:** [March 24, 2010, 8:18pm UTC](https://forum.kirupa.com/t/calling-a-fuction-from-external-swf/306935/1 "2010-03-24T20:18:03Z")

</div>

I have a main.swf that has a menu (mainMenu) and an external swf (ext.swf) that also has a menu (extMenu). When ext.swf is loaded into main.swf and when you CLICK a button from extMenu, I want that mainMenu.visible=false, and by pressing a button you can close the movieClip by clicking a button and the mainMenu.visible=true.

In main.swf, I’ve included:

function menuEstVis(eventObject:MouseEvent) {  
mainMenu.visible=true;  
trace(“menuVis”);  
}  
function menuVis() {  
addEventListener(MouseEvent.CLICK, menuEstVis);  
}  
function menuEstInv(eventObject:MouseEvent) {  
mainMenu.visible=false;  
trace(“menuInv”)  
}  
function menuInv() {  
addEventListener(MouseEvent.CLICK, menuEstInv);  
}

And in ext.swf, when you click a button from the extMenu:  
function actbtn(e:MouseEvent):void {  
var parentObjInv:Object = this.parent.parent as Object;  
parentObjInv.menuInv();}

And by clicking the close button:  
function closebtn(e:MouseEvent):void {  
var parentObjVis:Object = this.parent.parent as Object;  
parentObjVis.menuVis();} .

The first time it works (mainMenu.visible=0, and and the trace message is “menuInv” ).And by clicking the close button the mainMenu.visible=true but the trace message is “menuInv” followed by “menuVis”. Apparently, it does the two functions at the same time and the mainMenu does not disappear (mainMenu.visible=false) . How can I fix this.  
Thank you
