Random array sound selection problem
Hello,
I'm a gigantic AS3 noob so please be gentle with me. I have probably simply done something very stupid.
I have an animated character and a set of footstep sounds, and have set up code so that at a set point in the walk cycle a random footstep sound is played based on frame label selection. The following code is in the character movieclip:
function getRandomLabel():String {
var labels:Array = new Array("step1", "step2", "step3", "step4","step5", "step6", "step7", "step8");
var index:Number = Math.floor(Math.random() * labels.length);
trace (labels[index])
return labels[index];
}
step1, 2 etc refer to the frame labels of the sound movieclip I have nested inside the character movieclip, which contains the eight sounds on 8 frames with appropriate labels (plus an additional blank frame at the beginning).
At the frames in the character animation where I wish a footstep sound to play, I have the code:
this.soundtest.gotoAndStop(getRandomLabel());
'soundtest' is the name of the sound movieclip containing the footsteps. This works perfectly; I get a random sound at the right time on each footfall. The weird problem is that if the random label index returned is the same as the previous one (i.e. step1 and step1 again) the second sound does not play. This only happens if the same label is repeated, otherwise it works fine. So the footsteps have occasional breaks in them where 'something' prevents repeat sounds/array indices being played. What could be the problem here?
Thanks in advance.
