1 decade ago by dmen
In my game class I instantiate an entity that has a button in it. The button, is supposed to call a method in the main game class that instantiated it... How can I do this so I keep scope in the game class? Right now I do like so:
this.spDialog.show('l1intro', 'back', this.buttonBack, this);
and then in the spDialog the show method goes like:
show: function(whichDialog, b1, b1Func, b1Context){
and then I assign the callback and context:
this.callback = b1Func;
this.scope = b1Context;
and then I try to do:
this.callback.call(this.scope);
The function gets called, but inside the function, this is not the original scope...
this.spDialog.show('l1intro', 'back', this.buttonBack, this);
and then in the spDialog the show method goes like:
show: function(whichDialog, b1, b1Func, b1Context){
and then I assign the callback and context:
this.callback = b1Func;
this.scope = b1Context;
and then I try to do:
this.callback.call(this.scope);
The function gets called, but inside the function, this is not the original scope...