Return to Snippet

Revision: 19426
at October 23, 2009 10:53 by weavermedia


Initial Code
// setTimeout allows you to call a function after a specified delay along with arguments, which setTimer does not allow you to do
// You can even make it act like a loop if you call setTimeout within its called function

var dd:uint = 2000; // ms delay before function is called
var str:String = "Dog";
var mc:MovieClip = new MovieClip();

var timeoutExample:uint = setTimeout(delayedFunction, dd, str, "Cat", "Monkey", 0xFFDF1B, mc);

function delayedFunction():void
{
	trace("Delayed function ");
	if (arguments.length==0) {trace("No argumentys passed")};
	for (var i=0; i<arguments.length; i++)
	{
		trace(arguments[i]);
	}
	timeoutExample = setTimeout(loopedFunction, dd/2, Math.round(Math.random()*100));
}

function loopedFunction():void
{
	trace("Random number: "+arguments[0]);
	timeoutExample = setTimeout(loopedFunction, dd/2, Math.round(Math.random()*100));
}

Initial URL

                                

Initial Description

                                

Initial Title
Calling a function after a specified delay and pass arguments - not using Timer()

Initial Tags

                                

Initial Language
ActionScript 3