Menu.removeMenuItem()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

menuInstance.removeMenuItem()

Returns

A reference to the returned menu item (XML node). This value is undefined if there is no item in that position.

Description

Method; removes the specified menu item and all its children, and refreshes the menu.

Example

The following example creates a menu with three menu items and sets an interval to cause the menu to be displayed for a couple of seconds (2000 milliseconds). When the interval expires, the example calls the removeItem() function, which calls the removeMenuItem() method to remove the first item in the menu and redisplay it.

You first drag a Menu component to the library and then add the following code to Frame 1:

/**
 Requires:
  - Menu component in library
*/

import mx.controls.Menu;

// Create an XML object to act as a factory.
var my_xml:XML = new XML();

// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var menuDP_obj:Object = my_xml.addMenuItem("XXXXX");

// Add the menu items.
menuDP_obj.addMenuItem({label:"first Item"});
menuDP_obj.addMenuItem({label:"second Item"});
menuDP_obj.addMenuItem({label:"third Item"});

// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);

// Show and position the menu.
my_menu.show(100, 20);

// Call closeMenu after 2000 milliseconds.
var interval_id:Number = setInterval(removeItem, 2000, my_menu);
function removeItem(the_menu:Menu):Void {
    // Delete the first node item.
    var myItem_obj:Object = my_menu.getMenuItemAt(0);
    myItem_obj.removeMenuItem();
    clearInterval(interval_id);
    my_menu.show(100, 20);
}