What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [lib] setTimeout / setInterval

[lib] setTimeout / setInterval
Author: Message:
the DtTvB
Junior Member
**


Posts: 47
Reputation: 10
– / Male / –
Joined: Mar 2007
Status: Away
O.P. [lib] setTimeout / setInterval
This code allows you to set the timer/interval the same way you use in web pages (setTimeout, setInterval, clearTimeout, clearInterval)..

code:
var setTimeout;
var clearTimeout;
var setInterval;
var clearInterval;
var handleTimer;

function OnEvent_Timer( i ) {
    handleTimer ( i );
}

// An annonymous function, so it won't disturb any other global variables.
// for example, the currentTimer variable is not accessible from any other
// functions.
(function() {

    var currentTimer = 0; // The current timer ID.
    var timersData = [];  // Keeps all data about the timers...
   
    handleTimer = function(tid) {
        if (tid.substr(0, 12) == '_dttvb_timer') {
            var itid = (tid.substr(12) - 0); // convert to number.
            if (typeof timersData[itid] != 'undefined') {
                timersData[itid][0]();
                if (timersData[itid][1]) {
                    MsgPlus.AddTimer (tid, timersData[itid][2]);
                }
            }
        }
    };
   
    setTimeout = function(f, t) {
        var tid = ++currentTimer;
        timersData[tid] = [f, 0, t];
        MsgPlus.AddTimer ('_dttvb_timer' + tid, t);
        return tid;
    };
    setInterval = function(f, t) {
        var tid = ++currentTimer;
        timersData[tid] = [f, 1, t];
        MsgPlus.AddTimer ('_dttvb_timer' + tid, t);
        return tid;
    };

    clearTimeout = function(tid) {
        delete timersData[tid];
    };
    clearInterval = function(tid) {
        delete timersData[tid];
    };

})();

for example,

code:
function foo() {
    // do something
}
setTimeout (foo, 200);

Note that setTimeout ("foo()", 200); will not work.
The reference to the function should be passed in the first parameter, not string. Eval is evil.

This post was edited on 03-12-2007 at 12:28 PM by the DtTvB.
the DtTvB - My name has no meaning, but it's unique at least!
[Image: asj.gif]
03-12-2007 12:27 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On