# Menu Component and Window Component

**URL:** <https://forum.kirupa.com/t/menu-component-and-window-component/212984>\
**Category:** flash\
**Created:** [January 16, 2007, 4:00am UTC](https://forum.kirupa.com/t/menu-component-and-window-component/212984 "2007-01-16T04:00:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![davydany](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@davydany](https://forum.kirupa.com/u/davydany)\
**Post date:** [January 16, 2007, 4:00am UTC](https://forum.kirupa.com/t/menu-component-and-window-component/212984/1 "2007-01-16T04:00:22Z")

</div>

I have a dilema. I’m trying to create a flash application that is basically a rich text editor

well, I’m trying to make a menu component to open a window component which has a close button

here is a part of my code (attempt 1):

```php

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

var my_mb:MenuBar;

var myProfile:Menu = my_mb.addMenu("My Profile");
myProfile.addMenuItem({label:"View/Edit Profile Information", instanceName:"newInst"});
myProfile.addMenuItem({label:"See My Profile", instanceName:"openInst"});

//THE LISTENERS
var mbListener:Object = new Object();
mbListener.change = function(evt_obj:Object) {
 var menuItem_obj:Object = evt_obj.menuItem;
 switch (menuItem_obj.attributes.instanceName) {

  case "openInst":
  var my_win:MovieClip = PopUpManager.createPopUp(this, Window, true, {closeButton:true, contentPath:"openDialog"});
    var winListener:Object = new Object();
    winListener.click = function() {
        my_win.deletePopUp();
    };
    my_win.addEventListener("click", winListener);
  break;
}

```

\*\*The problem with this script: \*\*when I test the movie, the movie freezes and Flash asks do you want to disable the script and etc…

so I tried doing the same by attachMovie() :

```php

//THE STUFF FROM BEFORE
  switch (menuItem_obj.attributes.instanceName) {
  case "openInst":
    _root.attachMovie("Window","openInst",this.getNextHighestDepth());
    openDialog.setSize(623.9,310)
    openDialog.closeButton = true;
    openDialog.contentPath = "openDialog";
    openDialog.title = "Open Document";

//HERE IS THE PROBLEM:
    openDialog.close = function() {
        trace("Closing...");
        removeMovieClip(_level0.openInst);
    }
  break;

```

**The problem from the 2nd Code Box:** I can’t close the box. When I press the X, it won’t close it.

So…basically what I’m asking is…How do I call a Window Component from a Menu Bar Component and let the Window Component also close correctly when the user closes it.

Thanks in advance for your great help!
