Here is a very simple example in MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
contextMenu="{cm}"
creationComplete="init()">
<mx:TextArea id="myTA" x="10" y="10" width="200" height="100"/>
<mx:Script>
<![CDATA[
import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import mx.controls.Alert;
[Bindable] private var cm:ContextMenu;
private var labels:Array = ["red","green","blue"];
private function init():void {
cm = new ContextMenu();
cm.addEventListener(ContextMenuEvent.MENU_SELECT,onMenuSelect);
}
private function onMenuSelect(event:ContextMenuEvent):void {
cm.customItems = [];
for each (var label:String in labels) {
var item:ContextMenuItem = new ContextMenuItem(label);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
onMenuItemSelect);
cm.customItems.push(item);
}
}
private function onMenuItemSelect(event:ContextMenuEvent):void {
var item:ContextMenuItem =
event.currentTarget as ContextMenuItem;
Alert.show(item.caption);
}
]]>
</mx:Script>
</mx:Application>
--- In [email protected], Alex Harui <aha...@...> wrote:
>
> I'm pretty sure you can't alter the context menu for a TextArea unless you
> set both editable=false and selectable=false which sort of defeats its utility
>
> From: [email protected] [mailto:[email protected]] On
> Behalf Of cesarerocchi
> Sent: Saturday, November 22, 2008 6:30 AM
> To: [email protected]
> Subject: [flexcoders] Modify context menu of TextArea
>
>
> Hi,
>
> I am trying to modify the contextMenu which appears when I right-click a
> TextArea.
> Can I do it? How?
>
> Thanks in advance,
>
> -c.
>