Flex AIR 中的右键菜单

发布于 2025-01-04 15:24:22 字数 92 浏览 0 评论 0原文

我很难在 AIR 应用程序中右键单击时出现上下文菜单或某种 NativeMenu。有人可以指出我正确的方向或提供一点示例代码以便我在脑海中澄清吗?

谢谢!

I am having a really hard time getting a contextmenu or some sort of NativeMenu coming up on right click in my AIR app. Can someone point me in the right direction or provide a small bit of sample code so I clarify it in my mind?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

兮子 2025-01-11 15:24:22

这是空气应用程序中上下文菜单项的一个很好的示例

Adobe Air - 在树节点右键单击时添加上下文菜单

This is nice example of context menu item in air application

Adobe air - add context menu on right click of tree node

梦醒时光 2025-01-11 15:24:22

当然,

看看这个: http:// /help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html

以下是示例:

package {
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.ui.ContextMenuBuiltInItems;
    import flash.events.ContextMenuEvent;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.text.TextField;

    public class ContextMenuExample extends Sprite {
        private var myContextMenu:ContextMenu;
        private var menuLabel:String = "Reverse Colors";
        private var textLabel:String = "Right Click";
        private var redRectangle:Sprite;
        private var label:TextField;
        private var size:uint = 100;
        private var black:uint = 0x000000;
        private var red:uint = 0xFF0000;

        public function ContextMenuExample() {
            myContextMenu = new ContextMenu();
            removeDefaultItems();
            addCustomMenuItems();
            myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);

            addChildren();
            redRectangle.contextMenu = myContextMenu;
        }

        private function addChildren():void {
            redRectangle = new Sprite();
            redRectangle.graphics.beginFill(red);
            redRectangle.graphics.drawRect(0, 0, size, size);
            addChild(redRectangle);
            redRectangle.x = size;
            redRectangle.y = size;
            label = createLabel();
            redRectangle.addChild(label);
        }

        private function removeDefaultItems():void {
            myContextMenu.hideBuiltInItems();
            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomMenuItems():void {
            var item:ContextMenuItem = new ContextMenuItem(menuLabel);
            myContextMenu.customItems.push(item);
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
        }

        private function menuSelectHandler(event:ContextMenuEvent):void {
            trace("menuSelectHandler: " + event);
        }

        private function menuItemSelectHandler(event:ContextMenuEvent):void {
            trace("menuItemSelectHandler: " + event);
            var textColor:uint = (label.textColor == black) ? red : black;
            var bgColor:uint = (label.textColor == black) ? black : red;
            redRectangle.graphics.clear();
            redRectangle.graphics.beginFill(bgColor);
            redRectangle.graphics.drawRect(0, 0, size, size);
            label.textColor = textColor;
        }

        private function createLabel():TextField {
            var txtField:TextField = new TextField();
            txtField.text = textLabel;
            return txtField;
        }
    }
}

Sure,

Take a look at this: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html

Here is the example:

package {
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.ui.ContextMenuBuiltInItems;
    import flash.events.ContextMenuEvent;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.text.TextField;

    public class ContextMenuExample extends Sprite {
        private var myContextMenu:ContextMenu;
        private var menuLabel:String = "Reverse Colors";
        private var textLabel:String = "Right Click";
        private var redRectangle:Sprite;
        private var label:TextField;
        private var size:uint = 100;
        private var black:uint = 0x000000;
        private var red:uint = 0xFF0000;

        public function ContextMenuExample() {
            myContextMenu = new ContextMenu();
            removeDefaultItems();
            addCustomMenuItems();
            myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);

            addChildren();
            redRectangle.contextMenu = myContextMenu;
        }

        private function addChildren():void {
            redRectangle = new Sprite();
            redRectangle.graphics.beginFill(red);
            redRectangle.graphics.drawRect(0, 0, size, size);
            addChild(redRectangle);
            redRectangle.x = size;
            redRectangle.y = size;
            label = createLabel();
            redRectangle.addChild(label);
        }

        private function removeDefaultItems():void {
            myContextMenu.hideBuiltInItems();
            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomMenuItems():void {
            var item:ContextMenuItem = new ContextMenuItem(menuLabel);
            myContextMenu.customItems.push(item);
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
        }

        private function menuSelectHandler(event:ContextMenuEvent):void {
            trace("menuSelectHandler: " + event);
        }

        private function menuItemSelectHandler(event:ContextMenuEvent):void {
            trace("menuItemSelectHandler: " + event);
            var textColor:uint = (label.textColor == black) ? red : black;
            var bgColor:uint = (label.textColor == black) ? black : red;
            redRectangle.graphics.clear();
            redRectangle.graphics.beginFill(bgColor);
            redRectangle.graphics.drawRect(0, 0, size, size);
            label.textColor = textColor;
        }

        private function createLabel():TextField {
            var txtField:TextField = new TextField();
            txtField.text = textLabel;
            return txtField;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文