Helpw/flash + javaS

Hello-I am working on a project (website) mainly in Flash which incorporates many javaS pop-up windows–this is all embedded in an HTML page. How do I get one window to close upon opening the next (automatically, rather than relying on the viewer to close each time)??-I am using a simply written javaScript popup function…Thanks for any help!