16
Apr
08

Minimizing Flex’ default context menu

In case you want to add custom menu items to the default menu item of a Flex app, here is a small snippet to get you started:

Step one - Minimize the default contextual menu

// defaultMenu will keep our reference to the default menu of our browser-based
// Flex application
var defaultMenu:ContextMenu;

// Now, let's make the default menu as small as possible
defaultMenu = Application.application.contextMenu;
defaultMenu.hideBuiltInItems();

Step two - Add you own menu entry to the contextual menu

Then, let’t create a new menu item to be added to the default contextual menu.

// item is our new menu item
var item:ContextMenuItem = new ContextMenuItem("Some String");

// Add an event listener, which gets fired, if the user selected the menu item
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleStaticMenuItem);

// Finally, it's time to add the new menu item to the default menu
defaultMenu.customItems.push( item );

// Implement your own event handling routine here
public function handleStaticMenuItem( anEvent:Event ):void {

}

While it’s very simple to add a new menu entry, you can’t get rid of all Flash Player contextual menu entries: Even if you call hideBuildInMenu(), certain menu items will still be visible.

Once you deploy your Flex application as a standalone AIR application, you are free again, since AIR application don’t have default menu items.


0 Responses to “Minimizing Flex’ default context menu”


  1. No Comments

Leave a Reply