# Close Button in Window Not Working!

**URL:** <https://forum.kirupa.com/t/close-button-in-window-not-working/105018>\
**Category:** Uncategorized\
**Created:** [March 22, 2004, 9:53am UTC](https://forum.kirupa.com/t/close-button-in-window-not-working/105018 "2004-03-22T09:53:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kannan](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@Kannan](https://forum.kirupa.com/u/Kannan)\
**Post date:** [March 22, 2004, 9:53am UTC](https://forum.kirupa.com/t/close-button-in-window-not-working/105018/1 "2004-03-22T09:53:58Z")

</div>

**Flash Type:**  
Application using **forms**.

**Flash Version:**  
Flash MX 2004 Professional.

**Components Used:**  
Menu  
Window  
Alert  
Combo Box  
Label  
Text Field  
Radio Button  
Check Box

**Problem Area:**  
A Window Launched by the menu has a close button. The close button’s _Listener_ doesn’t work.

**Code Explanation with problem:**  
The Menu is created during run time.

The listener function in menu when clicked, calls a user defined function _launchWindow();_

The _launchWindow();_ creates the _Window_ with content path _frmCalculator_ and has the close button .

After calling the _launchWindow();_ the _Window_ with _frmCalculator_ is loaded.

But when the _close button_ is clicked the _myWindow.addEventListener(“click” , windowListener);_ is not working, and hence the

_windowListener.click = function()_ is not called at all.

**But if the _launchWindow();_ is called directly during loading the close button event works.**

I have attached the source code. Please help me.

//Source Code========================================

import mx.controls.Menu;  
import mx.controls.MenuBar;  
import mx.controls.Alert;  
import mx.managers.PopUpManager;  
import mx.containers.Window;

//launchWindow(“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7); //When this is used the close button works !!!

//Message Box Function  
function msgBox(msgContent,msgTitle){  
Alert.show(msgContent, msgTitle, Alert.OK, this, myClickHandler, “stockIcon”, Alert.OK);  
}

//Window Launcher Function  
//Arguments:  
//dataTitle: Title for the window  
//dataContent: the frmCalculator which is the second screen next to the first application created.  
//closeButton: true  
function launchWindow(dataContent,dataTitle,dataSX,dataSY,dataX,dataY){   
myWindow = PopUpManager.createPopUp (\_root, Window, false, {title:dataTitle, contentPath:dataContent, closeButton:true });

```
myWindow.setSize(dataSX,dataSY);
myWindow._x=dataX;
myWindow._y=dataY;
focusManager.setFocus(myWindow);

```

}

//Listener function for close button  
//This listener doesn’t work when the launchWindow() is called from the MENU Component.  
//But this listener works when the launchWindow() is called directly during load.  
windowListener=new Object();  
windowListener.click = function(){  
trace(“Close”);  
myWindow.deletePopUp();  
}  
myWindow.addEventListener(“click” , windowListener);

//Run Time Menu Creation  
// instances on the stage  
var menuBar:MenuBar;

// variables in this script  
var manager\_menu:Menu;  
/_=================  
MANAGER MENU  
=================_/  
//Main Menu  
manager\_menu = menuBar.addMenu(“Manager”);

//Sub Menu  
manager\_menu.addMenuItem({label:“Calculator”, instanceName:“calculatorInstance”, icon:“new”});  
manager\_menu.addMenuItem({label:“Exit”, instanceName:“exitInstance”});

// The listenered for the manager menu (and submenus)  
var managerListener:Object = new Object();  
managerListener.change = function(eventObj : Object) : Void {  
//selected\_ta = "Selected Application: " + eventObj.menuItem.attributes.label;  
//msgBox(selected\_ta,“Alert: Manager”);  
//statusBar.text=selected\_ta;  
[//barProgress.setProgress](https://barProgress.setProgress)(100,100);  
//launchWindow(frmCalculator,“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7);

```
switch (eventObj.menuItem) {
	//When this code calls the launchWindow(); the close button in the window doesn't work at all. The " myWindow.addEventListener("click" , 

```

windowListener); " is not working !!!  
case eventObj.menu.calculatorInstance: launchWindow(“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7); break;   
case eventObj.menu.exitInstance: fscommand(“quit”); break;   
}  
}

// register the listeners with the separate menus  
manager\_menu.addEventListener(“change”, managerListener);

Code========================================
