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
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 } }
thanks very much I will try this now, I am sure it will work
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.
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; } }
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
thank you!!!!! this was really useful, I am getting there (havn?t been on line for a while)
Don't see what you're looking for? Try a search.
|