Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : Timer or Counter


JRW32
3/14/2006 10:40:29 PM
I'm have a number of scenes and I want to play them in order but wait about 5
seconds between each scene. I guess I can just add frames until the 5 seconds
is up, but how can I use this in acitonscript. I couldn't find anything
helpful in searching the forums

Thanks.
blemmo
3/14/2006 11:38:13 PM
Check out setInterval, you can use it to add delays:
--
function doSomething(){
clearInterval(delay);
gotoAndPlay("Scene 2",1);
}

delay = setInterval(this, "doSomething", 5000);
--
The last line defines an interval that executes the 'doSomething' function
every 5000 ms (= 5 sec). We only need it to execute once, so the first thing in
'doSomething' is to delete the interval, and then go to the next scene.

As you're using scenes, you'll have to write a function for each scene,
because AFAIK you cannot use gotoAndPlay with scene names from variables, e.g.
var scene = "Scene 2";
gotoAndPlay(scene,1);
will not compile. If you decided to use frame labels instead, you could define
doSomething once and call it with different parameters:
--
function doSomething(label:String){
clearInterval(delay);
gotoAndPlay(label);
}

delay = setInterval(this, "doSomething", 5000, "frame20");
// or
delay = setInterval(this, "doSomething", 5000, "start");
--

hth,
blemmo
AddThis Social Bookmark Button