Textfield()-如何阻止鼠标右键菜单

发布于 2024-07-13 23:45:33 字数 53 浏览 5 评论 0原文

Textfield () - 如何防止出现鼠标右键菜单(具有复制、粘贴、全选等选项的菜单)。

Textfield () - how to prevent mouse right click menu from appearing (a menu having COPY, PASTE, SELECT ALL etc options).

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

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

发布评论

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

评论(4

酒废 2024-07-20 23:45:33

FlashPlayers 默认菜单项。

据我所知,您无法删除有意义的基本 FlashPlayer 项目(设置和关于)。

FlashPlayers 内置项目

您可以通过在编译时或在代码中指定它来删除最重要的项目(播放、暂停等):

contextMenu.hideBuiltInItems();

或在全局上下文中:

stage.showDefaultContextMenu = false; 

与 TextField 相关的菜单项< /strong>

文本字段的复制/粘贴/选择也是内置的,似乎您无法隐藏它们。 然而,您似乎确实想摆脱它们,这里有一个解决方法
下面的示例说明了如何在文本字段上添加透明按钮以转移鼠标行为:

package  
{
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.ui.ContextMenu;        


    public class TestText extends Sprite 
    {

        private var textField:TextField;

        public function TestText()
        {
            // Removes the inbuit items from the contextMenu

            var contextMenu:ContextMenu = new ContextMenu();
            contextMenu.hideBuiltInItems();
            this.contextMenu = contextMenu;

            // Adds a simple input TextField

            textField = addChild(new TextField()) as TextField;
            textField.type = TextFieldType.INPUT;
            textField.text = "Test Text";

            // Covers the TextField with a transparent shape

            var shape:Sprite = addChild(new Sprite()) as Sprite;
            shape.graphics.beginFill(0, 0);
            shape.graphics.drawRect(0, 0, textField.width, textField.height);
            shape.mouseChildren = false;

            // Listens to a click on the mask to activate typing

            shape.addEventListener(MouseEvent.CLICK, eventClickHandler);
        }

        private function eventClickHandler(event:MouseEvent):void
        {
            // Sets the focus to the underlaying TextField and makes 
            // a full selection of the existing text.

            stage.focus = textField;
            textField.setSelection(0, textField.text.length);
        }
    }
}

FlashPlayers default menu items.

As far as I know you cannot remove the basic FlashPlayer items (Settings and About) which make sense.

FlashPlayers inbuilt items

You can remove the top ones (Play, Pause, etc.) by either specifying it while compiling or from within the code:

contextMenu.hideBuiltInItems();

or within the global context :

stage.showDefaultContextMenu = false; 

TextField related menu items

The copy/paste/select being inbuilt as well for TextFields it doesn't seem you can hide them. However as it seems like you really want to get rid of them here's a workaround.
The example below illustrates how you can add a transparent button over the textField to sidetrack the mouse behavior:

package  
{
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.ui.ContextMenu;        


    public class TestText extends Sprite 
    {

        private var textField:TextField;

        public function TestText()
        {
            // Removes the inbuit items from the contextMenu

            var contextMenu:ContextMenu = new ContextMenu();
            contextMenu.hideBuiltInItems();
            this.contextMenu = contextMenu;

            // Adds a simple input TextField

            textField = addChild(new TextField()) as TextField;
            textField.type = TextFieldType.INPUT;
            textField.text = "Test Text";

            // Covers the TextField with a transparent shape

            var shape:Sprite = addChild(new Sprite()) as Sprite;
            shape.graphics.beginFill(0, 0);
            shape.graphics.drawRect(0, 0, textField.width, textField.height);
            shape.mouseChildren = false;

            // Listens to a click on the mask to activate typing

            shape.addEventListener(MouseEvent.CLICK, eventClickHandler);
        }

        private function eventClickHandler(event:MouseEvent):void
        {
            // Sets the focus to the underlaying TextField and makes 
            // a full selection of the existing text.

            stage.focus = textField;
            textField.setSelection(0, textField.text.length);
        }
    }
}
风为裳 2024-07-20 23:45:33

您是否尝试过使用自定义 InteractiveObject.contextMenu

have you tried with a custom InteractiveObject.contextMenu?

难得心□动 2024-07-20 23:45:33

将字段 selectable 属性设置为 false。

Set the fields selectable property to false.

桃扇骨 2024-07-20 23:45:33

我找到了隐藏 TextFields 的默认上下文菜单项的方法!

只需设置一个自定义上下文菜单,并隐藏内置项目。 现在,当您右键单击时,什么也没有发生!

 // hide cut/copy/paste
 var cm:ContextMenu = new ContextMenu();
 cm.hideBuiltInItems();
 textfield.contextMenu = cm;

I found a way to hide the default context menu items for TextFields!

Just set a custom context menu, and hide the inbuilt items. Now when you right click, nothing happens!

 // hide cut/copy/paste
 var cm:ContextMenu = new ContextMenu();
 cm.hideBuiltInItems();
 textfield.contextMenu = cm;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文