Window Component: deletePopUp() problem

What is the best practice for deleting Windows? I spawn multiple windows from a Tree component that is structured based on XML. I can get it to work if I just try to kill the first Window I spawn. If I spawn multiple ones, it does not work. Appears the EventListener cannot figure out which close button sends out its broadcast, on the current Window that has focus.

Here is the code snippet:

[left]var theSelectedNodeData = theSelectedNode.attributes.data; var theSelectedNodeLabel = theSelectedNode.attributes.label; //var theSelectedNodeWindow = theSelectedNode.attributes.label; trace("title "+theSelectedNodeLabel); trace(“file “+theSelectedNodeData); theSelectedNodeWindow = mx.managers.PopUpManager.createPopUp(_root, mx.containers.Window, false, {title:theSelectedNodeLabel+” Workspace”, contentPath:theSelectedNodeData, closeButton:true}); trace("the "+theSelectedNodeWindow); theSelectedNodeWindow.show; theSelectedNodeWindow.move(120, 0); theSelectedNodeWindow.setSize(400, 400); //add closeWindow listener for the workspaces Sars and Bioterror workspace windowListener2 = new Object(); trace(“got this far…”); windowListener2.click = function(evt) { focusWindow = focusManager.getFocus(); trace("focusWindow " + focusWindow); //_root.theSelectedNodeWindow.deletePopUp(); _root.focusWindow.deletePopUp(); }; _root.theSelectedNodeWindow.addEventListener(“click”, windowListener2);[/left]