Call function from other class

I have in view file code like this

class MyView extends Ui.View {

hidden var color;
.....
function highlight() {
findDrawableById("lbl_one").setText("111");
...
}
}

class GameViewDelegate extends Ui.BehaviorDelegate
{

function initialize() {
BehaviorDelegate.initialize();
}


function onKeyPressed( evt ) {

?????????[HTML][/HTML]
Sys.println("My function from other class is work!!");
return true;
}


How I can call function highlight() in onKeyPressed event?
  • How I can call function highlight() in onKeyPressed event?


    There are a few ways to handle this. The easiest way is to pass a reference to the view to the delegate, like this...

    class MyView extends Ui.View
    {
      function initialize() {
        View.initialize();
      }
    
      function highlight() {
        findDrawableById("lbl_one").setText("111");
      }
    }
    
    class GameViewDelegate extends Ui.BehaviorDelegate
    {
      hidden var _M_view;
    
      function initialize(view) {
        BehaviorDelegate.initialize();
        _M_view = view;
      }
    
      function onKeyPressed( evt ) {
        _M_view.highlight();
        return true;
      }
    }
    
    // when you create your view and delegate...
    var view = new GameView();
    var delegate = new GameViewDelegate(view);



    Travis