Flex4 使用 ContextMenu() 右键单击​​ Spark 列表

发布于 2024-10-20 10:24:41 字数 282 浏览 3 评论 0原文

我想向许多火花列表控件添加自定义右键单击。 我已尝试以下作为项目渲染器。 (根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丶情人眼里出诗心の 2024-10-27 10:24:41

我找到了问题/解决方案。如果有 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.

时光无声 2024-10-27 10:24:41

Christopher Huyler 发布了一些内容类似(源代码可在此处获取)。摘自文章:

首先从 Google 代码存储库获取 Javascript 代码。

第 1 步 – 设置自定义上下文菜单代码

在 Flex Builder 中创建一个新的 Flex 项目。将 rightclick.js 和 swfobject.js 复制到项目的 html-template 文件夹中。从这里开始,我必须进行一些更改...

  • 我修改了 RightClick.init() 函数以接受对象和容器值作为输入。这允许我将应用程序的名称作为对象传递,而不是每次都调用相同的东西。
  • 我在index.template.html 的标头中包含了rightclick.js 和swfobject.js。
  • 我向主体添加了一个名为“flashcontent”的新 div。
  • 我向 body 标记添加了一个 onload 处理程序来初始化 RightClick
  • ,我用新的 SWFObject(...) 替换了 AC_FL_RunContent(...),确保维护所有模板变量。

进行这些更改后,我验证了我的应用程序中没有出现右键单击上下文菜单。

第 2 步 – 侦听 rightClick 事件

接下来,我向应用程序的主 mxml 文件中添加了几行,以侦听当我右键单击应用程序时将调度的ExternalInterface 事件。

private function handleCreationComplete():void
{
    ExternalInterface.addCallback("rightClick", handleRightClick);
}

private function handleRightClick():void
{
    Alert.show("Right Click Success!");
}

第 3 步 – 将事件分派到正确的对象

将事件发送到主应用程序很容易,但我们实际上希望在右键单击事件发生时通知适当的子对象。由于我没有在应用程序中使用任何双击事件,因此我决定将每个右键单击事件视为双击事件。没有两键鼠标的用户(也称为 Mac 用户)只需双击即可获得相同的菜单,而拥有两键鼠标的用户只需右键单击即可。以下是我如何确保将事件分派到适当的对象。

private function handleRightClick():void
{
    var objects:Array = systemManager.getObjectsUnderPoint(
        new Point(mouseX,mouseY));
    if (objects.length>0)
    {
        var object:Object = objects[objects.length-1];
        var relatedObject:InteractiveObject;
        if (object is InteractiveObject)
            relatedObject = object as InteractiveObject;
        else if (object.parent && object.parent is InteractiveObject)
            relatedObject = object.parent;
        var event:MouseEvent = new MouseEvent(
            MouseEvent.DOUBLE_CLICK,true,false,mouseX,mouseY,
            relatedObject);
        object.dispatchEvent(event);
    }
}

我希望这有帮助!

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…

  • I modified the RightClick.init() function to accept an object and container value as input. This allows me to pass in the name of the application as the object instead of having it be called the same thing every time.
  • I included rightclick.js and swfobject.js in the header of index.template.html.
  • I added a new div to the body called “flashcontent”.
  • I added an onload handler to the body tag to initialize RightClick
  • I replaced AC_FL_RunContent(…) with new SWFObject(…) making sure to maintain all template variables.

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.

private function handleCreationComplete():void
{
    ExternalInterface.addCallback("rightClick", handleRightClick);
}

private function handleRightClick():void
{
    Alert.show("Right Click Success!");
}

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.

private function handleRightClick():void
{
    var objects:Array = systemManager.getObjectsUnderPoint(
        new Point(mouseX,mouseY));
    if (objects.length>0)
    {
        var object:Object = objects[objects.length-1];
        var relatedObject:InteractiveObject;
        if (object is InteractiveObject)
            relatedObject = object as InteractiveObject;
        else if (object.parent && object.parent is InteractiveObject)
            relatedObject = object.parent;
        var event:MouseEvent = new MouseEvent(
            MouseEvent.DOUBLE_CLICK,true,false,mouseX,mouseY,
            relatedObject);
        object.dispatchEvent(event);
    }
}

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文