Link to home
Start Free TrialLog in
Avatar of katyjack30096
katyjack30096

asked on

setinterval not working

I've got several sound clips running, one after the other. I'm trying to insert a pause of about 2 seconds between each clip. I want to keep the rest of the movie running, but just delay the loading of each clip. Right now, this is the way I've got it. (There's a function earlier in the code that sends the actionscript to this frame upon completion of the previous sound clip:

_root.showClip(slide2_mc,360,149,mx.transitions.Fly,0)
function wait(){
   play();
   clearInterval(IntervalID)
}
stop();
IntervalID = setInterval(wait,6000);

if (langFlag == "C") {
      _root.loadNextSound("Eng2.wav");
} else {
      _root.loadNextSound("Fr2.wav");
}

What's happening is that the code is blowing right through the stop(); and loading the next sound clip with no delay at all. If I put a trace on the wait function, I can see that the code is pausing 6 seconds and then running the wait function, but in meantime it's also running the rest of the script without stopping. What can I do to actually stop the script from running and wait 6 seconds?

Thanks -
Avatar of Montoya
Montoya

You can set a value to a varible every six seconds, and have the clip check for the value of the variable before running...

var okToPlay = no;

Before you tell the sound to play, set the variable to no.
When you're done with the set interval (after your pause) set the variable to yes.
Run an if/then statement that checks the value of okToPlay before playing the sound clip.

(since you're familiar w/ the code and since Im in a rush right now, I've avoided the code)

You can also code the whole thing without the variable by including your setinterval inside of your function. I like the first method simply because its easier to understand.

Montoya
ASKER CERTIFIED SOLUTION
Avatar of elhy
elhy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial