I'm developing a flex application and I want to add it a context menu. I got it with this code:
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myMenu.builtInItems;
defaultItems.print = false;
var item:ContextMenuItem = new ContextMenuItem("Go to google");
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
this.contextMenu = myMenu;
But I have a problem. The menu shows four default options (Settings, about flash...) I would like to hide them. With defaultItems.print = false; I hid the print option, but I don't know how to hide others. Does anybody know how to do that? Thanks.
There is a technique to hide the Settings, about flash etc. from the context menu in Flash. The high level concept is to use JavaScript in the HTML container to disable the right-click on top of the SWF. Capture the event and then forward it to your Flex app using the ExternalInterface API which allows you to call Flex functions from JavaScript. Call a function defined in your Flex app to display a custom ContextMenu with only the menu items you want. This sidesteps the hardwired behavior in Flash/Flex where a right mouse click always causes a ContextMenu with the Settings, About stuff to come up.
A detailed walkthrough can be found at this link.
As the reference for ContextMenu says,
You cannot remove the Settings menu item from the context menu. The Settings menu item is required in Flash so that users can access the settings that affect privacy and storage on their computers. You also cannot remove the About menu item, which is required so that users can find out what version of Flash Player they are using.
So you'll just have to live with the Settings
and About
items. For other default items, see the reference for ContextMenuBuiltInItems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With