Configurable ContextMenu API

The ContextMenu classes in ActionScript 3: ContextMenu, ContextMenuItem, ContextMenuBuiltInItems, provide a good base for working with context menus in Flex 2, however, they do not provide an intuitive API for developing and working with custom context menus.

Such is the case whereas an application requires the flexibility to dynamically add, remove, enable and disable ContextMenuItems at runtime. To meet the requirements for an application which needs to meet any of the criteria I just mentioned, developers have 2 options; either work with the ContextMenu classes directly or develop a more intuitive API to provide the required functionality. I prefer to roll my own APIs in these situations.

The ConfigurableContextMenu API allows developers to dynamically create custom context menus in which items can be added, removed, enabled, disabled and cloned dynamically at runtime. This opens up numerous possibilities such as adding individual context menus for each item in a DataGrid, or each node in a Tree, etc.

The ConfigurableContextMenu API addresses certain issues which fail silently in the ContextMenu class such as ContextMenuItem collision and so forth. Developers can add caption items that do not require a listener or command items which contain both a caption and a listener to handle the item when selected. Items can be removed, added, cloned, enabled and disabled dynamically at runtime. ContextMenus can be created with a listener which is invoked when the contextmenu is selected (right-click). ConfigurableContextMenus can be added to any InteractiveObject or sub-class of InteractiveObject.

The ConfigurableContextMenu API is published under the MIT license.

{ 1 comment to read ... please submit second! }

  1. Eric,
    Do you have any examples on using this api? I didn’t see any in the ASDoc.

    Thanks,
    -Luis

{ 0 Pingbacks/Trackbacks }