How can I set to load the function every 10 sec. e.g like
Firstly, load function a
after 10 sec, load function b
after 10 sec load function c
Do anyone know how to do that?
Printable View
How can I set to load the function every 10 sec. e.g like
Firstly, load function a
after 10 sec, load function b
after 10 sec load function c
Do anyone know how to do that?
you can use the setInterval to run a function every 10 seconds. what you would do though is to have it run a function that increments and then calls the incremented function
Code:setInterval(whichFunction, 10000);
function whichFunction(){
variable+=1
funcName+variable();
}
function funcName1(){
//code here
}
not tested so i am not 100% sure it works. but the setInterval statement will work for calling every 10 seconds.
I will try to work on it. THx
I had a chance to test the code i gave you and it will not work. I tried alot of different methods and the best one and only one that seems to work would be the switch case. use the following code for your routine.
this will run every 10 seconds based on the setInterval
Code:stop();
var variable:Number = 0;
whichFunction();
var intervalId = setInterval(whichFunction, 10000);
function whichFunction(){
variable++;
trace(variable);
switch(variable){
case 1:
funcName1();
break;
case 2:
funcName2();
break;
case 3:
funcName3();
break;
default:
trace("End of interval");
clearInterval(intervalId);
variable=0;
break;
}
}
function funcName1 () {
trace("This is function 1");
}
function funcName2 () {
trace("This is function 2");
}
function funcName3 () {
trace("This is function 3");
}
Hi,
This is can be done using the first method VI Knight posted:
code:
var counter:Number = 0;
whichFunction();
var intervalId = setInterval(whichFunction, 10000);
function whichFunction(){
counter++;
_root["funcName"+counter]();
}
function funcName1 () {
trace("This is function 1");
}
function funcName2 () {
trace("This is function 2");
}
function funcName3 () {
trace("This is function 3");
}
However, you'll need to have a lot of functions unless you cause it to loop:
code:
if (counter > 10) {
counter = 0;}
Perhaps if you say a bit more about what the functions do? Perhaps the same function could be used each time but with variable arguments?
that is how i was trying to do it first but i couldn't get the _root["funcName"+counter](); to work. I was using the wrong code (I didn't use the _root). that is why i went to the switch statement. this way is indeed shorter.
but i would use the clearInterval in the in teh if statement instead of just resetting the counter since he will most likely want to kill the process after it has run all the functions.
so the total code would look like this:Code:if (counter > totalFunctions) {
counter = 0;
clearInterval(intervalId);
}
Code:stop();
var variable:Number = 0;
var totalFunction = 3;
whichFunction();
var intervalId = setInterval(whichFunction, 10000);
function whichFunction(){
variable++;
trace(variable);
_root["funcName"+variable]();
if (counter > totalFunctions) {
counter = 0;
clearInterval(intervalId);
}
}
function funcName1 () {
trace("This is function 1");
}
function funcName2 () {
trace("This is function 2");
}
function funcName3 () {
trace("This is function 3");
}
you could do it using onEnterFrame by doing some calculations of how many frames would be played in 10 seconds and then check a number if its that.