View Full Version : random sound
tham007
September 11th, 2002, 11:34 AM
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 !:(
tham007
September 11th, 2002, 11:52 AM
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!!
jsk
September 19th, 2002, 09:46 AM
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()
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.