How can I create a context menu on the fly in a textArea in AS3/AIR?

129 Views Asked by At

I am migrating an application from Flex/Flash to Flex/AIR 32.

Many years ago I began using the flextenibles SpellCheck module. It creates a custom component for textArea which will underline misspelled words then display misspelled word in a context menu.

I have successfully migrated it, however the only way to get the custom context menu to popup is by very carefully right mouse clicking the squiggly line under the text, not the text itself. When I right click the text it displays a default context menu. It actually never gets to the function to build custom context menu. I have place the following code in a variety of places in the custom class which extends mx.controls.textArea;

private function creationCompleteHandler(event:Event):void
{
    this.contextMenu = new ContextMenu;
    this.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,showMenu);
}

Including in the constructor and its original location createChildren with the same behavior.

In the Flex/flash version right clicking the text would bring up the custom context menu.

Edit:

As I do more debugging, I find "this.textField" from within the component is firing MouseEvent.CONTEXT_MENU, and it is never getting to the "this.contextMenu" event.

1

There are 1 best solutions below

0
Paul Stearns On

Well I found a work around.

I used the following to create the event listener;

    this.textField.addEventListener(MouseEvent.CONTEXT_MENU,showMenu);

Then I changed the handler to use the event data from a mouseEvent instead of contextMenuEvent, this seems to work.