Flex4 使用 ContextMenu() 右键单击 Spark 列表
我想向许多火花列表控件添加自定义右键单击。 我已尝试以下作为项目渲染器。 (根据 Flex 4 烹饪书)。
完整的渲染代码在这里 http://pastebin.com/Kx8tJ1cY
当我右键单击 Spark 列表时,我只需得到Adobe 默认上下文菜单。 这与我添加任何代码之前的默认行为相同。
谁能告诉我如何在 Flex 4 中添加右键单击列表项目。
请,谢谢。
I would like to add custom right clicks to a number of spark list controls.
I have tried the following as an item renderer. (as per the flex 4 cook book).
Full Render code here http://pastebin.com/Kx8tJ1cY
When I right click on the Spark List I simply get the Adobe Default Context menu.
This is the same default behaviour I had before I added any code to this.
Could anyone tell me how to add right clicks to List Items in Flex 4.
Please and Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了问题/解决方案。如果有 Vbox 或选项卡导航器,则无法使用上下文菜单。这很疯狂,因为这意味着我无法正确进行相对布局或体面的可变宽度设计。
引用自:http://help.adobe。 com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html
例如,如果 DataGrid 控件是 TabNavigator 或 VBox 容器的子级,则 DataGrid 控件不能有自己的上下文菜单。
I found the problem/solution. You cant use context menus if there are Vboxes or Tab Navigators. Which is insane because it means I cant do relative layout properly or decent variable width design.
Quoted from: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html
For example, if a DataGrid control is a child of a TabNavigator or VBox container, the DataGrid control cannot have its own context menu.
Christopher Huyler 发布了一些内容类似(源代码可在此处获取)。摘自文章:
首先从 Google 代码存储库获取 Javascript 代码。
第 1 步 – 设置自定义上下文菜单代码
在 Flex Builder 中创建一个新的 Flex 项目。将 rightclick.js 和 swfobject.js 复制到项目的 html-template 文件夹中。从这里开始,我必须进行一些更改...
进行这些更改后,我验证了我的应用程序中没有出现右键单击上下文菜单。
第 2 步 – 侦听 rightClick 事件
接下来,我向应用程序的主 mxml 文件中添加了几行,以侦听当我右键单击应用程序时将调度的ExternalInterface 事件。
第 3 步 – 将事件分派到正确的对象
将事件发送到主应用程序很容易,但我们实际上希望在右键单击事件发生时通知适当的子对象。由于我没有在应用程序中使用任何双击事件,因此我决定将每个右键单击事件视为双击事件。没有两键鼠标的用户(也称为 Mac 用户)只需双击即可获得相同的菜单,而拥有两键鼠标的用户只需右键单击即可。以下是我如何确保将事件分派到适当的对象。
我希望这有帮助!
Christopher Huyler posted something similar (source code available here). From the article:
Start out by grabbing the Javascript code from Google's code repository.
Step 1 – Setup custom context menu code
Create a new Flex project in Flex Builder. Copy rightclick.js and swfobject.js into the html-template folder of your project. From here, I had to make several changes…
After making these changes, I verified that no right-click context menu appears in my application.
Step 2 – Listen for the rightClick event
Next I added a few lines to the main mxml file of my application to listen for the ExternalInterface event that will be dispatched when I right-click my appliction.
Step 3 – Dispatch an event to the correct object
Getting the event to the main application is easy, but we actually want the appropriate child object to be notified when the right-click event occurs. Since I am not using any double-click events in my application I decided I would treat every right-click event like a double-click event. Users without a two button mouse (aka Mac users) can simply double-click to get the same menu while users with a two button mouse just have to right-click. Here is how I make sure the event is dispatched to the appropriate object.
I hope this helps!