tham007
September 11, 2002, 2:34pm
1
I’m a beginner and I’m trying to make a button playing sound randomly each time you press it :
I’ve imported 10 sounds, and i want to play randomly 1 sound from 5 sounds I define from the 10 of the library…each time i press on the button.
pleeeeeeeeaaaz help !
system
September 11, 2002, 2:52pm
2
It’s me again
I’ve try that for only 2 sounds and it looks like it works!
on (release) {
if (random (2)<1) {
son2.stop();
} else {
son2.start(0,1 );
}
}
it’s my first try so please understand my …weakness on this and be sure i’m open to any advice!!
system
September 19, 2002, 12:46pm
3
You might like to try …
Export your 10 sounds with the linkage:
s11, s12, s13, … s20
When you want a sound use
randomSound=new Sound();
randomSound.attachSound(“s”.concat(Math.floor(Math.random()*10)+10));
randomSound.Start();
or, if you want to give your sounds descriptive names …
Export your 10 sounds with the linkage:
ding, ping, crash …
When you want a sound use
soundList= new Array (“ding”,“ping”,“crash”, “boom”)
randomSound=new Sound ()
randomSound.attachSound(soundList[Math.floor(Math.random()*soundList.length)])
randomSound.Start()