Copy link to clipboard
Copied
I'm having trouble getting the submenu to work on this right-click ContextMenu.
Here is my code:
var ignContext:ContextMenuItem = new ContextMenuItem("Ignition Status");
var ignSubContext:ContextMenu = new ContextMenu;
var onContext:ContextMenuItem = new ContextMenuItem("On");
var offContext:ContextMenuItem = new ContextMenuItem("Off");
ignSubContext.addItem(onContext);
ignSubContext.addItem(offContext);
ignContext.submenu = ignSubContext;
When I right-click, I see the "Ignition Status" with the little arrow indicating that it has a submenu, but the submenu does not list anything when I mouse-over it or click on it. I used this same method when I created the File drop-down menu with submenus, but it doesn't seem to work correctly here.
Edit:
I should also note that "ignContext" is added to myContextMenu:ContextMenu then I set this.contextMenu = myContextMenu.
Copy link to clipboard
Copied
show your relevant code.
and, line 2 should be new ContextMenu();
Copy link to clipboard
Copied
I fixed those, but it didn't make a difference.
The whole code:
//defined at top level
var myContextMenu:ContextMenu = new ContextMenu();
var backContext:ContextMenuItem;
var forwardContext:ContextMenuItem
//setup context menu
myContextMenu.removeAllItems();
myContextMenu.hideBuiltInItems();
var contextArray:Array = new Array;
backContext = new ContextMenuItem("Back");
forwardContext = new ContextMenuItem("Forward");
var meterContext:ContextMenuItem = new ContextMenuItem("Meter");
meterContext.separatorBefore = true;
meterContext.checked = (Utility.METER_ON);
if (Utility.CUR_SYS_REC != 1)
{
meterContext.enabled = false;
}
var cirOpContext:ContextMenuItem = new ContextMenuItem("Circuit Operation");
var settingsContext:ContextMenuItem = new ContextMenuItem("Settings");
var printContext:ContextMenuItem = new ContextMenuItem("Print");
var engContext:ContextMenuItem = new ContextMenuItem("Engine Status");
var runningContext:ContextMenuItem = new ContextMenuItem("Running");
var notRunningContext:ContextMenuItem = new ContextMenuItem("Not Running");
var engSubContext:ContextMenu = new ContextMenu();
engSubContext.addItem(runningContext);
engSubContext.addItem(notRunningContext);
engContext.submenu = engSubContext;
var ignContext:ContextMenuItem = new ContextMenuItem("Ignition Status");
var ignSubContext:ContextMenu = new ContextMenu();
var onContext:ContextMenuItem = new ContextMenuItem("On");
var offContext:ContextMenuItem = new ContextMenuItem("Off");
ignSubContext.addItem(onContext);
ignSubContext.addItem(offContext);
ignContext.submenu = ignSubContext;
var speedContext:ContextMenuItem = new ContextMenuItem("Speed");
speedContext.visible = false;
if (Utility.CUR_SYS_REC != 1)
{
speedContext.visible = true;
}
contextArray.push(backContext,forwardContext,meterContext, cirOpContext, settingsContext, printContext, engContext, ignContext, speedContext);
//add all items
for (var i:int = 0; i < contextArray.length; i ++)
{
myContextMenu.addItem(contextArray);
}
checkArrows(null);
this.contextMenu = myContextMenu;
myContextMenu.addEventListener(Event.SELECT, contextItemSelected);
addEventListener(MouseEvent.RIGHT_MOUSE_UP, rightClicked);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now