0

Timer help

I'm new to the WDK and have mananged to get the very basics under control (i.e. creating snippets, sidebars and fullscreen views). I'm starting to look at other areas, one of them being timers. I have a very simple class that instantiates a timer with the purpose of dumping out a log statement (this isn't meant for any production purposes, just experimenting with the WDK). The code I have is as follows:

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

Extends: KONtx.system.FullscreenView,

config: {
count: 1
},

createView: function() {

//Setup some controls
.
.
.

//Set up timer
KONtx.utility.timer.setInterval(this.updateCount(),1000);
},


updateCount: function()
{
log("> > > > > > > here");
}
});


This works fine. The problem I have is if I try to pass an argument to the interval handler. Let's say in the example above I want the update the count each time the updateCount method is called, so I change the code to be the following.

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

Extends: KONtx.system.FullscreenView,

config: {
count: 1
},

createView: function() {

//Setup some controls
.
.
.

//Set up timer
KONtx.utility.timer.setInterval(this.updateCount(this),1000);
},


updateCount: function(myobj)
{
log("> > > > > > > "+myobj.count);
myobj.count++;
}
});



The problem I'm having is that the timer fires once, then immediately prints the following error message:

CODEBOX
'' is not a valid handler for 'onTimerFired'


the '' part of the message is confusing me as I've specified this.updatedCount(...) as the handler. What am I doing wrong? smile.gif Is there a better way to pass in arguments to a handler?

I'm using the latest WDK (downloaded it this weekend, ywe-wdk-1.0.0.0-i386) on a debian (5.x) VM, with the Samsung 1.2 simulator and the dump out of my /dump platform.backend.devinfo is as follows

CODEBOX
/dump platform.backend.devinfo
EM 00:04:07:072: [T:3983] dumpCmd: print('Object "platform.backend.devinfo":'); _dump(platform.backend.devinfo);
WD 00:04:07:072: [T:3983] Object "platform.backend.devinfo":
WD 00:04:07:072: [T:3983] Dumping object...
WD 00:04:07:072: [T:3983] appid: com.yahoo.widgets.tv.container
WD 00:04:07:072: [T:3983] appver: 1.2.31.C
WD 00:04:07:072: [T:3983] brand: TV Device Brand
WD 00:04:07:072: [T:3983] class: TV Device Class
WD 00:04:07:072: [T:3983] deviceid: TV Device Id
WD 00:04:07:072: [T:3983] deviceinfo: wdkversion=1.0.0.0
WD 00:04:07:072: [T:3983] dockversion: 1.2.31.C
WD 00:04:07:072: [T:3983] fwversion: 1.2.25.C
WD 00:04:07:073: [T:3983] hwversion: 0.1
WD 00:04:07:073: [T:3983] lang: en
WD 00:04:07:073: [T:3983] location: 95124
WD 00:04:07:073: [T:3983] man: SEC-VD 1.2
WD 00:04:07:073: [T:3983] model: TV Device Model
WD 00:04:07:073: [T:3983] region: US
WD 00:04:07:073: [T:3983] swversion: 0.1
WD 00:04:07:073: [T:3983] yweres: 960x540
WD 00:04:07:073: [T:3983] yweversion: 5.4.2

by
9 Replies
  • Eek... I should have double proofed my snippets, the line that reads

    CODEBOX
    log("> > > > > > > "+myobj.count);


    should of course say

    CODEBOX
    log("> > > > > > > "+myobj.config.count);


    sorry for any confusion :)
    0
  • Try this. I am not able to test it right now, but thought is might help.

    CODE
    var self = this;
    KONtx.utility.timer.setInterval(this.updateCount(self),1000);
    0
  • That doesn't seem to work either. If I just replace this with say a string like 'foo', and change the code so it looks like what is below I still get the same error too. It looks like there's something wrong with how I'm expecting parameter passing to an event handler to work, but it's stumping me as to what :)});
    0
  • Based on what you are trying to do, I think this will accomplish what you need. Try this.

    CODE
    var myClass = new KONtx.Class({
    ClassName: 'MyTimerClass',

    Extends: KONtx.system.FullscreenView,

    config: {
    count: 1
    },

    createView: function() {

    //Set up timer
    this.myobj = myobj;

    var self = this;
    KONtx.utility.timer.setInterval(self.updateCount(),1000);
    },


    updateCount: function()
    {
    log("> > > > > > > "+this.myobj);
    log("> > > > > > > "+this.config.count);
    }
    });
    0
  • nope, no dice :)
    0
  • Hi Les,

    QUOTE (Les C @ Mar 2 2010, 10:26 PM) <{POST_SNAPBACK}>
    CODE
    '' is not a valid handler for 'onTimerFired'

    the '' part of the message is confusing me as I've specified this.updatedCount(...) as the handler. What am I doing wrong? :)- Ben
    0
  • Oh, and if you want access to your config object, you can do it like this:

    CODE
    KONtx.utility.timer.setInterval(this.updateCount.bindTo(this), 1000);


    or like this:

    CODE
    var that = this;
    KONtx.utility.timer.setInterval(function () {
    that.updateCount();
    }, 1000);


    - Ben
    0
  • Ben, that worked like a charm! Thank you very much :)
    0
  • Les - I just say that I mistyped my example the below will also work.

    CODE
    var self = this;
    KONtx.utility.timer.setInterval(self.updateCount,1000);


    Ben is correct by calling "self.updateCount" with the (), you are passing in the result of the function not handing the function to the timer.

    Great example Ben.
    0
  • Recent Posts

    in Getting Started / Beginners - Yahoo! TV Widgets