0

setText inside the events section

Hello

I would like to update the text into a control using the setText('a text') method inside the events section of a button.

I read the manual but all the samples put a single Log(' a text') instruction inside the events section. Why ?.

Here is my code. Its fails and shows the error message:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!ERROR!ERROR!ERROR!ERROR!ERROR!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Type Error: this.controls has no properties (mifile.js line .... )


CODEBOX
var MainView = new KONtx.Class({
ClassName: 'MainView',

Extends: KONtx.system.SidebarView,

createView: function() {

this.controls.Boton1 = new KONtx.control.TextButton({
label: "Boton primero",
guid: "boton1ID",
styles: {
width: Theme.viewSpecs.SIDE_BAR.width,
height: KONtx.utility.scale(35),
vOffset: 0,
}
}).appendTo(this);

this.controls.Boton2 = new KONtx.control.TextButton({
label: "Boton segundo",
guid: "boton2ID",
events: {
onSelect: function(event) {
this.controls.Boton1.setText("TEXT CHANGED");
}
},
styles: {
width: Theme.viewSpecs.SIDE_BAR.width,
height: KONtx.utility.scale(35),
vOffset: this.controls.Boton1.outerHeight,
}
}).appendTo(this);

}
});


What is the mistery of the events section? , please help.

Thanks a lot. I apreciate your work.


Raul de Frutos (Spain)
--------------------

by
3 Replies
  • The event handler is (by default) executed in the scope of the element, not in the scope of the listener method's parent object, the custom object's properties are not available through the this property as one might expect. There are two approaches that I know of:

    CODE
    var self = this;
    this.controls.Boton2 = new KONtx.control.TextButton({
    events: {
    onSelect: function(event) {
    self.controls.Boton1.setText("TEXT CHANGED");
    }
    }}).appendTo(this);


    or

    CODE
    this.controls.Boton2 = new KONtx.control.TextButton({
    events: {
    onSelect: function(event) {
    this.owner.controls.Boton1.setText("TEXT CHANGED");
    }
    }}).appendTo(this);
    0
  • Great, great, great.

    Thanks a lot.

    It works nice now.

    Raul
    ------
    0
  • Here's a third method for purely academic purposes:

    CODE
    this.controls.Boton2 = new KONtx.control.TextButton({
    events: {
    onSelect: (function(event) {
    this.controls.Boton1.setText("TEXT CHANGED");
    }).bindTo(this)
    }}).appendTo(this);
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets