0

Creating Own Functions

Hi guys, I just wanna ask if we can create our own function in Kontx Framework. Below is an example of my function

CODE
      
addTesting: function(x,y){
return x + y;
}


After which i call this method and they produce me an error addTesting is undefined.
Is there any other way i can declare my own functions?
Thanks in advance

by
6 Replies
  • QUOTE (Wei loon Ang @ Mar 20 2011, 06:44 PM) <{POST_SNAPBACK}>
    Hi guys, I just wanna ask if we can create our own function in Kontx Framework. Below is an example of my function

    CODE
          
    addTesting: function(x,y){
    return x + y;
    }


    After which i call this method and they produce me an error addTesting is undefined.
    Is there any other way i can declare my own functions?
    Thanks in advance

    Yes, you can define your own functions.

    It's a scoping problem. In other words, the scope in which you're calling that function doesn't contain a reference to that function. So, you'll have to provide some more context. Please paste in your code and include how you're calling the function.
    0
  • Hi, thanks for the quick reply .. I m just creating random functions to test it out. So below is my sample code.

    CODE
        

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

    Extends: KONtx.system.SidebarView,



    createView: function() {
    this.controls.button1 = new KONtx.control.TextButton({
    label: "Play Video",
    guid: "button1",
    events: {
    onSelect: function(event) {
    print(addTesting(1,2));
    KONtx.application.loadView('view-Player', { PlaylistID: 1 });
    }
    },
    styles: {
    width: Theme.viewSpecs.SIDE_BAR.width,
    height: KONtx.utility.scale(35)
    }
    }).appendTo(this);

    var offset = this.controls.button2.outerHeight;
    new KONtx.control.EmptySpace({
    styles: {
    vOffset: offset,
    height: Theme.viewSpecs.SIDE_BAR.height - offset
    },
    }).appendTo(this);
    },

    cell_Creator: function() {


    //We need to setup a "Cell" to be created inside the Grid

    var gridcell = new KONtx.control.GridCell({
    id: 'forMap',

    styles: {

    width: this.width

    },

    events: {

    onSelect: function () {},

    }

    });



    /*gridcell.imageBox = new KONtx.element.Container({

    styles: {

    backgroundColor: '#EEEEEE',

    hOffset: 100,

    vOffset: 5,

    width: 80,

    height: 68 }

    }).appendTo(gridcell);



    gridcell.OneMap = new KONtx.element.Image({

    styles: {

    'hAlign': 'top',

    'vAlign': 'left',
    width: 80,
    height: 68

    }

    }).appendTo(gridcell.imageBox); */




    return gridcell;

    },
    _addTesting: function(x,y){
    return x + y;
    },

    });


    The function was created right at the bottom and it was called in the createView button1 onselect portion.
    Is there anything wrong with it?
    0
  • QUOTE (Wei loon Ang @ Mar 20 2011, 08:11 PM) <{POST_SNAPBACK}>
    Hi, thanks for the quick reply .. I m just creating random functions to test it out. So below is my sample code.

    CODE
        

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

    Extends: KONtx.system.SidebarView,



    createView: function() {
    this.controls.button1 = new KONtx.control.TextButton({
    label: "Play Video",
    guid: "button1",
    events: {
    onSelect: function(event) {
    print(addTesting(1,2));
    KONtx.application.loadView('view-Player', { PlaylistID: 1 });
    }
    },
    styles: {
    width: Theme.viewSpecs.SIDE_BAR.width,
    height: KONtx.utility.scale(35)
    }
    }).appendTo(this);

    var offset = this.controls.button2.outerHeight;
    new KONtx.control.EmptySpace({
    styles: {
    vOffset: offset,
    height: Theme.viewSpecs.SIDE_BAR.height - offset
    },
    }).appendTo(this);
    },

    cell_Creator: function() {


    //We need to setup a "Cell" to be created inside the Grid

    var gridcell = new KONtx.control.GridCell({
    id: 'forMap',

    styles: {

    width: this.width

    },

    events: {

    onSelect: function () {},

    }

    });



    /*gridcell.imageBox = new KONtx.element.Container({

    styles: {

    backgroundColor: '#EEEEEE',

    hOffset: 100,

    vOffset: 5,

    width: 80,

    height: 68 }

    }).appendTo(gridcell);



    gridcell.OneMap = new KONtx.element.Image({

    styles: {

    'hAlign': 'top',

    'vAlign': 'left',
    width: 80,
    height: 68

    }

    }).appendTo(gridcell.imageBox); */




    return gridcell;

    },
    _addTesting: function(x,y){
    return x + y;
    },

    });


    The function was created right at the bottom and it was called in the createView button1 onselect portion.
    Is there anything wrong with it?

    You'd call that function like this:

    CODE
    this.getView()._addTesting()

    The this keyword is scoped to the TextButton context, but your custom method is scoped to your view.

    Note that you named it _addTesting but in your sample code you're calling it without the underscore.
    0
  • It works perfectly fine, Thanks a lot Ben.
    0
  • QUOTE (Wei loon Ang @ Mar 20 2011, 10:25 PM) <{POST_SNAPBACK}>
    It works perfectly fine, Thanks a lot Ben.

    :)
    0
  • its work very good thanks for your help i ll use it in my ukash
    0

Recent Posts

in General - Yahoo! TV Widgets