0

Been tearing my hair out for ages trying to get my custom ContextMenu to apply to a TextArea, It will just display the default (copy, paste ect...).

        import mx.events.FlexEvent;

        public var nm:NativeMenu = new NativeMenu();
        public var cm:ContextMenu = new ContextMenu();

        protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
        {
            cm.clipboardMenu = true;

            var cmi:ContextMenuItem = new ContextMenuItem("ctest");
            cm.addItem(cmi);

            TA.contextMenu = cm;
        }

given TA is an mx TextArea in MXML

i'm really stumped!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
bigtallbill
  • 621
  • 6
  • 12
  • Found a solution: var txt:TextField = TA.mx_internal::getTextField() as TextField; txt.contextMenu = cm; placed after "TA.contextMenu = cm;" will allow the custom elements to show – bigtallbill Apr 12 '11 at 10:52
  • Hi @bigtallbill, and welcome on SO, post your solution as an answer and check it as a solved, or delete question. Try not to leave questions in open state. – Igor Milla Apr 12 '11 at 11:08
  • I tried but there was a 24 hour limit for new users. luckily andrewpthorp posted the answer :) – bigtallbill Apr 14 '11 at 06:53

1 Answers1

1

Just to put a full set of code for everyone to see:

var cm:ContextMenu = new ContextMenu();

var menuitem:ContextMenuItem = new ContextMenuItem("Check Spelling");
menuitem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleContextMenuEvent);
mainMenu.addItem(menuitem);

textArea.contextMenu = mainMenu;
var txt:TextField = textArea.mx_internal::getTextField() as TextField;
txt.contextMenu = mainMenu;

Hope this helps!

andrewpthorp
  • 4,998
  • 8
  • 35
  • 56