2016-06-07 78 views
-2

默认情况下,火花文本区域有一个内置的文本菜单与“剪切”,“复制”,“粘贴”,“删除”等选项。如何禁用Actionscript 3文本区域的默认上下文菜单?

我想用一个自定义,以取代该文本菜单,但我在使用禁用默认的一个问题。

在第一次添加自定义一个还后我得到了默认的文本菜单,然后从第二次我收到定制的ContextMenu。

我使用下面的代码的textarea:

<s:TextArea id="txtArea" width="100%" height="100%" borderVisible="false" focusAlpha="0.01" 
      verticalScrollPolicy="off" selectionHighlighting="always" styleName="TextBox" 
      needsSoftKeyboard="true" focusRect="false" buttonMode="true" useHandCursor="true" mouseChildren="true"/> 

并使用下面的代码添加自定义文本菜单右侧鼠标到文本区:

eventMap.mapListener(view.txtArea , MouseEvent.RIGHT_MOUSE_DOWN ,onRightMouseDown); 

private function onRightMouseDown(e:MouseEvent):void 
    { 
     var item1:ContextMenuItem = new ContextMenuItem("Cancel", true); 
     var item2:ContextMenuItem = new ContextMenuItem("Select", true); 

     var contextMenu:ContextMenu = new ContextMenu(); 
     contextMenu.hideBuiltInItems(); 
     contextMenu.customItems.push(item1); 
     contextMenu.customItems.push(item2); 

     view.txtArea.contextMenu = contextMenu; 
    } 

但我不知道为什么默认的ContextMenu第一次来。

所以任何人有一个想法,为什么它正在发生或者我做错了吗?

回答

1

你得到原来的上下文菜单中的第一次的原因是因为你没有把它关闭,直到第右键发生后。每次点击右键时,您也不必要地重建上下文菜单。

为了解决这个问题,你需要把你在onRightMouseDown函数中的代码放到你的类构造函数中,或者如果你没有,可以在swf运行后立即运行。这只需要发生一次。

+0

嗨@Glitcher我试图把我的代码到类的构造函数,并试图把代码变成创作完成,但在两种情况下我得到的第一个右键单击默认的上下文菜单。 – Ashish

0

我已经添加了对整个应用

addEventListener(MouseEvent.RIGHT_CLICK, function (... rest):void 
{ 
}) 

和defaultContextMenu被禁用。

1

以下代码解决我的问题:

var contextMenu = new ContextMenu(); 
contextMenu.hideBuiltInItems(); 
contextMenu.clipboardMenu = false; 
contextMenu.addItem(new ContextMenuItem("Start Select")); 
contextMenu.addItem(new ContextMenuItem("Start Copy")); 

(txtArea.textDisplay as RichEditableText).contextMenu = contextMenu; 

而不是把自定义上下文菜单直接进入textarea的控制,如果我们将穿上RichEditableText,就上方,然后,将解决这个问题。

相关问题