Textfield () - 如何防止鼠标右键菜单出现(具有复制、粘贴、全选等选项的菜单)。
Tom
问问题
2290 次
4 回答
1
您是否尝试过自定义InteractiveObject.contextMenu?
于 2009-02-23T11:50:56.623 回答
1
将字段selectable
属性设置为 false。
于 2009-02-23T12:00:05.743 回答
1
FlashPlayers 默认菜单项。
据我所知,您无法删除有意义的基本 FlashPlayer 项目(设置和关于)。
FlashPlayers 内置项目
您可以通过在编译时或在代码中指定它来删除顶部的(播放、暂停等):
contextMenu.hideBuiltInItems();
或在全球范围内:
stage.showDefaultContextMenu = false;
TextField 相关菜单项
TextFields 的复制/粘贴/选择也是内置的,您似乎无法隐藏它们。但是,您似乎真的想摆脱它们,这是一种解决方法。下面的示例说明了如何在 textField 上添加一个透明按钮来转移鼠标行为:
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);
}
}
}
于 2009-02-24T00:29:28.703 回答
1
我找到了一种方法来隐藏TextFields的默认上下文菜单项!
只需设置一个自定义上下文菜单,并隐藏内置项目。现在,当您右键单击时,什么也没有发生!
// hide cut/copy/paste
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
textfield.contextMenu = cm;
于 2011-10-28T12:06:14.807 回答