Playing random sound in array
Hey guys,
I'm new to AS3, still learning. I just read a little about arrays in the book I was learning from, and after looking at some online stuff, thought I'd try to do something simple with one.
What I'm trying to do is save a bunch of sounds (different dog barks) in an array and then when I press the button, it plays a random sound from that array. Here's what I have so far :
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class Sound2 extends MovieClip
{
var bark1:Bark1;
var bark2:Bark2;
var bark3:Bark3;
var bark4:Bark4;
var bark5:Bark5;
var bark6:Bark6;
var soundChannel:SoundChannel;
var barkArray:Array = [Bark1, Bark2, Bark3, Bark4, Bark5, Bark6];
public function Sound2()
{
barkButton.addEventListener(MouseEvent.CLICK, onBarkButtonClick);
bark1 = new Bark1();
bark2 = new Bark2();
bark3 = new Bark3();
bark4 = new Bark4();
bark5 = new Bark5();
bark6 = new Bark6();
soundChannel = new SoundChannel();
function onBarkButtonClick(event:MouseEvent):void
{
var barkNo = Math.round(Math.random() * 5);
soundChannel = (barkArray[barkNo]).play();
}
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
When I try to press the button, I get this error message :
TypeError: Error #1006: play is not a function.
at MethodInfo-22()
I used trace and saw the numbers from barkNo were fine, I think it's just something about the array. I've also spent a few hours trying to do it different ways, but still nothing. How can I play a random sound from an array? And am I storing the information correctly? I'm not sure what I'm missing, any help would be great.
Thanks
