0

redefine Styles after creation

Is there a way to access or redefine styles of a KONtx.element after the object is created?

Say I have a KONtx.control.Grid with cellCreator() and cellUpdater() functions. In the cellCreator() I define a KONtx.element.Text within the cell. When i update it within the cellUpdater(), I would like to update the style information with different color, vOffset, hOffset, ect. based upon the data that's passed to the cellUpdater(). If I try to reference the cell.text.styles it says it's undefined, even though cell.text. is clearly a KONtx.element.Text object.

I believe the style is undefined for any object, if you try and access it after it's creation. Is this a design choice? How would I be able to access the vOffset, hOffset, color, ect. styles after the object's creation?

by
4 Replies
  • The easiest way is to call <element>.setStyles() and pass in the styles block like you would normally in the config.
    0
  • QUOTE (Jeremy Johnstone @ May 11 2009, 11:08 AM) <{POST_SNAPBACK}>
    The easiest way is to call <element>.setStyles() and pass in the styles block like you would normally in the config.



    that worked perfectly, thanks
    0
  • In the same idea Is there a way to set the events of an element dynamically ? like a setEvents() method ?

    Thanks
    0
  • QUOTE (cotreaudaubonne @ May 12 2009, 11:37 PM) <{POST_SNAPBACK}>
    In the same idea Is there a way to set the events of an element dynamically ? like a setEvents() method ?

    Thanks



    This one is a bit trickier, but here's an example:

    CODE
    // at init time
    var button = new KONtx.control.Button({
    events: {
    onSelect: function(event) {
    // do something
    }
    }
    });


    // after init time
    (function(event) {
    // do something
    }).subscribeTo(button, "onSelect", button);


    In the late example, we are subscribing the anonymous function to the button's onSelect event and scoping it to the button (the third parameter to subscribeTo). This is virtually identical to the first form. One difference with the later form is that you can subscribe multiple functions to the same handler where the first form can only take a single handler (but doesn't block you from adding more later).

    -Jeremy
    0
  • QUOTE (Jeremy Johnstone @ May 13 2009, 09:47 AM) <{POST_SNAPBACK}>
    This one is a bit trickier, but here's an example:

    CODE
    // at init time
    var button = new KONtx.control.Button({
    events: {
    onSelect: function(event) {
    // do something
    }
    }
    });


    // after init time
    (function(event) {
    // do something
    }).subscribeTo(button, "onSelect", button);


    In the late example, we are subscribing the anonymous function to the button's onSelect event and scoping it to the button (the third parameter to subscribeTo). This is virtually identical to the first form. One difference with the later form is that you can subscribe multiple functions to the same handler where the first form can only take a single handler (but doesn't block you from adding more later).

    -Jeremy


    Great ! It worked fine. Thanks for your help.

    Jean
    0

Recent Posts

in General - Yahoo! TV Widgets