# Controlling interval between sound within a loop?

**URL:** https://forum.kirupa.com/t/controlling-interval-between-sound-within-a-loop/141952
**Category:** Uncategorized
**Created:** [March 24, 2005, 1:54pm UTC](https://forum.kirupa.com/t/controlling-interval-between-sound-within-a-loop/141952 "2005-03-24T13:54:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Flashmatazz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/flashmatazz/32/140_2.png) [@Flashmatazz](https://forum.kirupa.com/u/Flashmatazz)
#### Post date: [March 24, 2005, 1:54pm UTC](https://forum.kirupa.com/t/controlling-interval-between-sound-within-a-loop/141952/1 "2005-03-24T13:54:12Z")

</div>

Hi,

would anyone have an idea how this could best be done?

I have a sound object which should loop continuously but the speed of looping should be dependant on the speed of a moving mc on stage.

I tried something like this:

```auto

Sound.prototype.playAtInterval = function(nMillis)
{
	var currentSound = this;
	var nInterval = nMillis + this.duration;
	var nCounter = 0;
	var startTime;
	var isInitialized = false;
	var soundTimer_mc = _root.createEmptyMovieClip("soundTimer_mc", 1);
	soundTimer_mc.onEnterFrame = function()
	{
		if (!isInitialized)
		{
			isInitialized = true;
			startTime = getTimer();
		}
		var currentTime = getTimer();
		var nDiff = currentTime - (startTime + (nCounter * nInterval));
		if (nDiff > nCounter * nInterval)
		{
			currentSound.start();
			nCounter++;
		}
	}
}
var mySound = new Sound();
mySound.attachSound("spinner_sound");
mySound.playAtInterval(10);

```

but when the interval is too small the sound doesn’t loop evenly, I guess because of the onEnterFrame.

Any other ideas?
