Ui.Menu.addItem() takes a symbol

I'm sure this is by design, but I'm not sure I understand the motivation. The second parameter to the Ui.Menu method addItem() is a Symbol. Unfortunately this makes it difficult to do dynamic menus. If I want to allow the user to select from a dynamic list, I have to assign symbols to each menu item position, then use a lookup table to determine which symbol was associated with which item.

Is there a better way to do this, or could addItem() be updated to take a Lang.Number instead?
  • Former Member
    Former Member
    Create some dummy handlers and an array of spare symbols. Sorry no time for fancy code at the mo

    class MainMenuDelegate extends myMenuInputDelegate {

    function onMenuItem(item) {
    if(:id_custom_0 == item) {
    // do something
    }
    else if(:id_custom_1 == item) {
    // do something
    else if......
    }
    }


    var sym = [:id_custom_0,:id_custom_1];


    menu.addItem("New menu item", sym[0]);
  • Yup. That is the lookup table idea that I was talking about above.

    As it turns out, the solution is much simpler than that. You can pass a Number. You can also get the value (in the onMenuItem() handler) and use that as if it were a Number. It looks like this works just fine as long as the values that you use are sufficiently small. I can easily use the index in my existing data array as the integer, and all is well. I don't like it, but the workaround is much simpler than what I was expecting to have to do.