all groups > flash actionscript > november 2005 >
You're in the

flash actionscript

group:

four on/off sound buttons


four on/off sound buttons birtan
11/23/2005 11:47:32 PM
flash actionscript:
Hello all!
Does anyone know how to make four Sound on/off buttons (side by side, each
with its own sound) that can be played all at the same time, two together, one
by one, none etc. I have tried so many different versions of on/off sound
buttons and am about to give up. There must be a genious out there that can
help!
Thanks,
Birta
Re: four on/off sound buttons kglad
11/24/2005 12:00:00 AM
for(var j=1;j<=4;j++){ // <- for-loop used to avoid repeated coding
rclip=_root.createEmptyMovieClip("mc"+j,j); // <- each sound needs a timeline
so you can have independent control of each sound
_root["s"+j]=new Sound(rclip); // _root.s1,_root.s2 are the sound objects
// the line below attaches a separate sound to each sound object
_root["s"+j].attachSound("id"+j); // define these linkage ids
_root["btn"+j].jvar=j; //<- this lets button j know it's button j
_root["btn"+j].onPress=function(){
if(!this.toggle){ //<-this is the toggle test. this.toggle is false to start
_root["s"+this.jvar].start(); //<- so this branch executes first and starts
the sound associated with this button
} else { // this branch executes every odd numbered button press
_root["s"+this.jvar].stop(); // and stops the sound
}
this.toggle=!this.toggle; // this toggles the toggle variable
}
}
Re: four on/off sound buttons NSurveyor
11/24/2005 12:00:00 AM
Re: four on/off sound buttons birtan
11/24/2005 12:00:00 AM
thanks very much
I will try this now, I am sure it will work

Re: four on/off sound buttons NSurveyor
11/24/2005 12:00:00 AM
Just to let you know how you hae to set up your Flash file...

Import your 4 sounds into the Library. Right click on the first one, select
Linkage... Then, select Export for Actionscript, and type in id1 for the
linkage identifier. Hit OK. Do the same thing with the other three sounds but
give them the instance names, id2, id3, and id4.Then, on the _root timeline,
you need to have 4 buttons, with the instance names, btn1, btn2, btn3, and btn4.
Re: four on/off sound buttons kglad
11/24/2005 12:00:00 AM
Re: four on/off sound buttons kglad
11/24/2005 12:53:21 AM
you need four different sound objects and they each need to be defined relative
to a different movieclip:

for(var j=1;j<=4;j++){
rclip=_root.createEmptyMovieClip("mc"+j,j);
_root["s"+j]=new Sound(rclip);
_root["s"+j].attachSound("id"+j); // define these linkage ids
_root["btn"+j].jvar=j;
_root["btn"+j].onPress=function(){
if(!this.toggle){
_root["s"+this.jvar].start();
} else {
_root["s"+this.jvar].stop();
}
this.toggle=!this.toggle;
}
}
Re: four on/off sound buttons birtan
11/24/2005 10:26:28 AM
thanks a lot

I am afraid this is a bit to advanced for me (so no wonder why I have not succeeded), I would be really grateful if you could explain a bit further.....

birta
Re: four on/off sound buttons birtan
11/29/2005 9:43:13 PM
thank you!!!!! this was really useful,
I am getting there
(havn?t been on line for a while)

Re: four on/off sound buttons kglad
11/30/2005 1:46:54 AM
AddThis Social Bookmark Button