Callbacks

Former Member
Former Member
I get an error, what am I doing wrong?

class MyClass
{
function doOnce()
{
System.println("test");
var a = method(:ontTest);
a.invoke();
}

function onTest()
{
System.println("passed");
}
}


results in

test
Failed invoking <symbol>
Invalid Value
@PC = 0x10000068
@PC = 0x10000068
@PC = 0x10000029
Invalid Value
Invalid Value


If I try

var a = method(:ontTest);
//System.println(a instanceof Method);


I get the same error.
  • Looks like a simple typographical error. Your function is onTest, but the symbol passed to method is ontTest.
  • Former Member
    Former Member over 10 years ago
    Oops....
    I made this test because I didn't get it to work. Have been staring at it for an hour :S

    Thanks.
  • Former Member
    Former Member over 10 years ago
    But then I'm still stuck with this:

    function pushMenu()
    {
    var menu = new MainMenu();
    Ui.pushView(menu, new MainMenuInputDelegate(), Ui.SLIDE_RIGHT);
    }


    class MainMenu extends Ui.Menu
    {
    function initialize()
    {
    setTitle("My menu");

    addItem("Start", method(:onStart));
    }

    function onStart()
    {
    Systen.println("onStart");
    }
    }

    class MainMenuInputDelegate extends Ui.MenuInputDelegate
    {
    function onMenuItem(item)
    {
    System.println("onMenuItem");
    System.println(item instanceof Method);
    item.invoke();
    }
    }


    Shouldn't this work? I don't want a long if/else construct in my onMenuItem, so I thought I'd just pass a method as item id.

    N.B I know for most cases I should use a resource for a menu, but the items won't always be the same.
  • Former Member
    Former Member over 10 years ago
    Pfff. Solved it. Thanks.

    class MainMenu extends Ui.Menu
    {
    function initialize()
    {
    setTitle("My menu");

    addItem("Start", :onStart);
    }
    }

    class MainMenuInputDelegate extends Ui.MenuInputDelegate
    {
    function onMenuItem(item)
    {
    var a = method(item);
    System.println("onMenuItem");
    System.println(a instanceof Method);
    a.invoke();
    }

    function onStart()
    {
    System.println("onStart2");
    }
    }
  • Yeah. I discovered that one a while ago. Symbols are fun.