Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable sounds 1

Status
Not open for further replies.

brainpudding

Technical User
Sep 29, 2002
84
US
I am working on a project where when the user mouses over a certain movie clip it play one of 3 sounds at random, there are motions that go for each sound also, my problem is that i need it to not work if there is one of those 3 sounds already playing... so you dont get it playing over itself. this is what i have so far

//clerk actions
csound0 = new Sound();
csound0.attachSound("Welcome");
csound1 = new Sound();
csound1.attachSound("heritage");
csound2 = new Sound();
csound2.attachSound("get");
btnclerk.onRollOver = function(){
clerkaction = Math.round(Math.random()*2);
if(clerkaction == 0){
_root.btnclerk.gotoAndStop(1);
csound0.start(0,1);
}
if(clerkaction == 1){
_root.btnclerk.gotoAndStop(1);
csound1.start(0,1);
}
if(clerkaction == 2){
csound2.start(0,1);
_root.btnclerk.gotoAndStop("point");
}
}
 
try this

csound = new Sound();
btnclerk.onRollOver = function(){
csound.stop();
clerkaction = Math.round(Math.random()*2);
if(clerkaction == 0){
_root.btnclerk.gotoAndStop(1);
csound.attachsound("welcome")
csound.start(0,1);
}
if(clerkaction == 1){
_root.btnclerk.gotoAndStop(1);
csound.attachsound("heritage")
csound.start(0,1);
}
if(clerkaction == 2){
csound.attachsound("get")
csound.start(0,1);
_root.btnclerk.gotoAndStop("point");
}
}
 
that works as well but my next problem is i want it so once they mouseover it and the sound starts they cant initiate another one ... so it has to finish the one its on before it moves on to the next one. because with the way it is it cuts them off before the sound finishes.
 
Add and set an extra variable like sound_playing = true; when the sound is started, setting it to false again when it's not, and also add it to your if statements to condition the fact that a new sound can't be played if one is already playing.

Regards,

cubalibre2.gif
 
csound = new Sound();
btnclerk.onRollOver = function(){
csound.stop();
clerkaction = Math.round(Math.random()*2);
if(clerkaction == 0){
_root.btnclerk.gotoAndStop(1);
csound.attachsound("welcome")
csound.start(0,1);
sound_active=true;
}
if(clerkaction == 1){
_root.btnclerk.gotoAndStop(1);
csound.attachsound("heritage")
csound.start(0,1);
sound_active=true;
}
if(clerkaction == 2){
csound.attachsound("get")
csound.start(0,1);
sound_active=true;
_root.btnclerk.gotoAndStop("point");
}
}


that will work for the setting it to true .. but what would u use to set it to false? onsoundcomplete?
 
Most probably onSoundComplete...

But you should also add to all your if statements...

if(clerkaction == 0 && sound_active == true){...



Regards,

cubalibre2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top