Page 1 of 1

server side setTimeout

Posted: 03 Jan 2007, 14:54
by Francois
me again ;-)

I guess the title is self explain...

Posted: 03 Jan 2007, 15:15
by Dr_Malito
in the docs there is a function called setInterval(), maybe are the function you are looking for.

myInterval = setInterval("simpleThread", 1000, params)

Posted: 07 Jan 2007, 09:03
by Lapo
setTimeout()
Here's an example.

This is the setTimeout implementation: just copy the code below in your extension or make it an external .as file and import it using #include

Code: Select all

function setTimeout(scope, fn, delay, params)
{
	var args = []
	for (var i = 3; i < arguments.length; i++)
		args.push(arguments[i])
		
	var timer = new Packages.java.util.Timer()
	var task = new Packages.java.util.TimerTask()
	{
		run:function()
		{
			fn.apply(scope, args)
		}
	}
	
	timer.schedule(task, delay)
}
Here's a simple example of usage:

Code: Select all

function delayedFunction(s,n,b)
{
	trace("I was called with the following arguments:")
	
	trace("String : " + s)
	trace("Number : " + n)
	trace("Boolean: " + b)
	
}

setTimeout(this, delayedFunction, 1000, "Hello world!", 123456, true)
hope it helps :)

Posted: 09 Jan 2007, 10:09
by Francois
Working great !!!

Thank you a lot, this is another (little but very useful) step forward for SFS :D

I'm developing on 1.5.0 but our production server is using 1.4.0...
Will it work on 1.4.0 ?

I cannot access the prod server at this time so if you can confirm this, I'd be even happier... :?:

Posted: 21 Feb 2007, 04:21
by jflowers45
This is very useful. Thanks!