Hide default options in right click context menu in flex

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 08:53:38

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1576472/hide-default-options-in-right-click-context-menu-in-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!