This content has been marked as final. Show 7 replies
Look this in the help files in the setInterval description;
"If interval is less than the SWF file's frame rate (for example, 10 frames per second [fps] is equal to 100 millisecond intervals), the interval function is called as close in time to the value of interval as possible. Executing long, memory-intensive scripts during an interval causes delays."
How many fps your movie have ?
I'm running 30fps. Thanks, I'll try increasing the frame rate.
"kyugawa" <email@example.com> wrote in message news:firstname.lastname@example.org...
>I am trying to develop a simple drum synth in Flash 8 using multiple
> setInterval functions to play short drum samples in unison. My problem is that
> the setInterval plays inconsistantly for example, I have the system play one
> sample every 300ms and another at 600ms. Theoretically one should play twice as
> fast as the other and match a beat every 600ms, but it doesn't it seems that
> the interval is going either two fast or two slow. I am working on a new IMac
> G5 with a gig of ram so I highly doubt its the computer performance. If anyone
> as any ideas or suggestions on how to lock down a consistant interval please
> let me know. Thanks a lot!
setInterval is not that accurate because it is tied to the frame rate. I find that if I want higher precision I need to use a
setInterval of 1ms and then use getTimer to see how much time has elapsed (and also a frame rate of 30). With a goal of 300ms I get
301 to 302 ms
In this example my G4 note and my B4 note play within 3ms of each other.
snd1 = new Sound(mc1);
snd2 = new Sound(mc2);
nowTime = getTimer(); // current time
// play the b4 note once every 300ms
b4time = nowTime - startTimeB4; // calculate elapsed time
if(b4time >= 300)
boxb4.text = b4time;
startTimeB4 += 300; // for next time
snd1.stop(); // in case still playing
// play the g4 note once every 300ms
g4time = nowTime - startTimeG4; // calculate elapsed time
if(g4time >= 300)
boxg4.text = g4time;
startTimeG4 += 300; // for next time
snd2.stop(); // in case still playing
id1 = setInterval(timerThing, 1); // 1 ms interval (but it can't do it that fast)
I don't think precision greater than about 2ms is possible with Flash and slower computers probably do worse than fast ones.
never rely on onEnterFrame or on setInterval .. both are unreliable.
However, if you do all your calcs based on actual elapsed time sine last
call (by comparing getTimer() values), then it won't matter which you use.
Thanks a lot for all the help. I'm currently using that method (getTimer()) and it seems to be within 1-3 ms accurate. I'm assuming that there isn't any other way in flash to get pinpoint accuracy on playing notes.
Unless your tempo (beats per second) is an integer multiple of your frame rate (frames per second). Then you will never ever get it to work properly in actionscript. Even if your tempo *is* then it is likely you will still have problems.
> Unless your tempo (beats per second) is an integer multiple of your frame
> (frames per second). Then you will never ever get it to work properly in
> actionscript. Even if your tempo *is* then it is likely you will still
If you use a setInterval with a very short interval and use getTimer to
adjust your timing, then it should be possible to get VERY close to what you
want. Won't be perfect though. It just depends on what level of
imperfection you're happy with