server side setTimeout

Post here your suggestions for new possible features in SmartFoxServer.

Moderators: Lapo, Bax

Post Reply
Francois
Posts: 35
Joined: 15 Mar 2006, 14:00

server side setTimeout

Post by Francois »

me again ;-)

I guess the title is self explain...
Dr_Malito
Posts: 18
Joined: 13 Dec 2006, 20:52
Location: Chile
Contact:

Post 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)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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 :)
Lapo
--
gotoAndPlay()
...addicted to flash games
Francois
Posts: 35
Joined: 15 Mar 2006, 14:00

Post 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... :?:
jflowers45
Posts: 63
Joined: 11 Jul 2006, 20:52

Post by jflowers45 »

This is very useful. Thanks!
How you doin?
Post Reply