-
OnsoundComplete - loop
I have two soundfiles that I want to loop after each other.
I think it´s best to use OnSoundComplete and I used it before. But in this case I want to loop between two different soundfiles and i can´t figure out how to do it.
This is how the code looks now.
s1=new Sound();
s1.attachSound("key1");
s1.start(0,10);
}
s1.onSoundComplete = function(){
s2=new Sound();
s2.attachSound("key2");
s2.start();
s2.onSoundComplete = function(){
s1.start(0,10);
}
-
Just modify only the array to add more sounds or to change the number of time each individual sounds repeats:
Code:
var index:Number = 0;
var aSounds:Array = [{sound:"key1", repeat:10}, {sound:"key2", repeat:1}]
function playSound():Void
{
iteration = 0;
snd = new Sound();
snd.attachSound(aSounds[index]["sound"]);
snd.start(0, aSounds[index]["repeat"]);
snd.onSoundComplete = playNextSound;
}
function playNextSound():Void
{
index++;
if(index == aSounds.length) index = 0;
playSound();
}
playSound();
-