Select to view content in your preferred language

Context menu in 2.3.1 not working

940
3
05-11-2011 08:41 AM
MichaelBartlett
Regular Contributor
In 2.1, I was able to add a context menu by doing the following (see code below). 
I moved to 2.3.1 and added the same code to the new MapManager.MXML
Now, the items do not show up when I right click.  Am I forgetting something?

import mx.core.FlexGlobals;

[Bindable]
private var cm:ContextMenu;

Private Function Init(): void
{
...
  // Added for Context menu

  var cmi:ContextMenuItem = new ContextMenuItem("Copy Lat, Long to clipboard", true);
  cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);

  cm = FlexGlobals.topLevelApplication.contextMenu;
  cm.hideBuiltInItems();
   
  MovieClip(systemManager).contextMenu = cm;
   
  cm.customItems = [cmi,cmi3];
  cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenu_menuSelect);

}
Tags (2)
0 Kudos
3 Replies
MehulChoksey
Esri Contributor
could you try following in MapManager.mxml:
.
.
.

        Alert.noLabel = noLabel;
                });
                var cmi:ContextMenuItem = new ContextMenuItem("Copy Lat, Long to clipboard", true);
                
                if (map.contextMenu)
                {
                    // call contextMenu dynamically so this will compile in AIR
                    if (map.contextMenu["customItems"] is Array)
                    {
                        (map.contextMenu["customItems"] as Array).push(menuItem);
                        (map.contextMenu["customItems"] as Array).push(cmi);
                    }
                    else if (map.contextMenu["addItem"])
                    {
                        map.contextMenu["addItem"](menuItem);
                    }
                }
0 Kudos
MichaelBartlett
Regular Contributor
That worked. Thank you very much.

I am guessing that the way I was doing it was adding the context menu of something else besides the map?

Also, would I need to add to this section too?
...
else if (map.contextMenu["addItem"])
{
map.contextMenu["addItem"](menuItem);
map.contextMenu["addItem"](cmi); }
0 Kudos
MehulChoksey
Esri Contributor
Yes. Thats correct.
0 Kudos