Flex:组件的自定义上下文菜单
我有一个 Flex 应用程序,使用 Flash Player(而不是 AIR)运行,其中包含一个我想在其上放置自定义上下文菜单的 Tree
。
尝试只做
,但这没有做任何事情。
去搜索,并在某处找到了一些 Adobe 文档中的引用
在 Flex 或 Flash Builder 中,只有应用程序中的顶级组件才能具有上下文菜单。例如,如果 DataGrid 控件是 TabNavigator 或 VBox 容器的子级,则 DataGrid 控件不能拥有自己的上下文菜单。
所以向上,尝试每个父元素,直到到达我的
元素,这与他们写的一致。
尝试制作一个 Flex 组件,基于包含我的树的组(默认)以及顶级元素上的上下文菜单,希望它能工作,但无济于事。
还有其他我还没有找到的方法来管理这个问题吗?
我用来创建菜单的代码:
var menuItems:Array = [];
var rename:ContextMenuItem = new ContextMenuItem("Rename");
rename.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, renameSelectedHandler);
menuItems.push(rename);
menu.customItems = menuItems;
menu.hideBuiltInItems();
I have a Flex application, running with Flash Player, not AIR, that contains a Tree
that I would like to put a custom context menu on.
Tried just doing <mx:Tree ... contextMenu="{MyClassWithStatic.menu}">
, but that didn't do anything.
Went searching, and found this quote from some Adobe docs somewhere
In Flex or Flash Builder, only top-level components in the application can have context menus. For example, if a DataGrid control is a child of a TabNavigator or VBox container, the DataGrid control cannot have its own context menu.
so went upwards, trying each parent element until I reached my <Application>
-element, which is consistent with what they wrote.
Tried making a Flex component, based on Group (the default) which contained my tree, and the context menu on the top-level element there, hoping it would work, but to no avail.
Is there any other way to manage this that I haven't found yet?
The code I use to create the menu:
var menuItems:Array = [];
var rename:ContextMenuItem = new ContextMenuItem("Rename");
rename.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, renameSelectedHandler);
menuItems.push(rename);
menu.customItems = menuItems;
menu.hideBuiltInItems();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是对的,上下文菜单仅适用于顶级组件。这是 Flex 的一个限制,很烦人,而且一开始就不应该存在。您无能为力,因为除了使用一些 Javascript 技巧之外,没有其他方法可以捕获事件,但即使如此,它也不会告诉您单击的位置。
如果我是你,我会忘记这个概念,并在可能的情况下完全放弃使用右键单击。
You're right, the contextmenu only works on top level components. It's a limitation of Flex which is annoying and shouldn't be there in the first place. There's not much you can do since there is no way to capture the event other than using some Javascript trickery, but even then, it doesn't tell you where you were clicking.
If I were you, I would just forget the concept and go away from using right click altogether if possible.
我不能确定,因为所有代码都不存在。但你似乎忽略了你自己的研究。不要使用您的新组件或任何“包含”您的树的组件。然后只需将树粘贴到您的应用程序中即可。
另外,我记得 TreeItemRenderer 与其他 UI 组件中的不一样。也许,首先使用数据网格测试您的“菜单”代码并确保它有效。祝你好运
I can't be sure, as all the code isn't' there. But you seem to have ignored your own research. Don't use your new component, or anything which "contains" your tree. Then just stick the Tree in your application.
Also I've a memory of TreeItemRenderer not being the same as in other UIcomponents. Maybe, test your "menu" code with a Datagrid first and make sure it works. Good luck
我自己没有尝试过,但是在阅读了 上的评论后http://michael.omnicypher.com/2007/02/flex-trees-with-context-menu_14.html 看起来您可以向树的项目渲染器添加上下文菜单。
文章和评论位于 http:// /blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/ 也值得一看。
I did not try it myself, but after reading the comments on http://michael.omnicypher.com/2007/02/flex-trees-with-context-menu_14.html it looks like you could add a context menu to the tree's item renderer.
The article and comments at http://blog.arc90.com/2008/04/21/adding-a-contextmenu-to-a-flex-tree/ are worth a look too.