简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM