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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

turning audio off universally 2

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
0
0
US
I'd like to have an audio off and on button for use in a game. The sounds in the game only play when the user does something successfully or unsuccessfully (like drag an object to the correct box). I have not figured out a way to have the user click an audio off button and have subsequent sounds not play (when the user does something to cause a sound to play). Any help would be appreciated.
 
AS1/AS2 code:
Code:
my_btn.onPress = function(){
    stopAllSounds();
}
This will stop all sounds playing.

Regards,

Martin

Computing Design And Services:
 
How would I program/play the sounds to play if I use this code to turn them off? I have the sounds playing when a user successfully drags and drops an object - so I have the audio play inside a movieclip with just the audio right on the stage.
 
you just start the sounds again like you normally would... the code I gave you stops all current sounds playing... but you can easily restart them like normal.

Regards,

Martin

Computing Design And Services:
 
What I'd like to happen is once the user clicks the audio off button that no sounds will play again even if the user does something that normally would cause a sound to play - so in essence I am not looking for a button to just stop the audio once but permanently.

It would be nice to have an audio on button that would turn the audio back on but I would be happy just to have an audio off button that turned the sound off permanently.
 
A mute button would work. I am using timeline sounds with movieclips. I know this is old code but I just have it arranged so when the user correctly does something a telltarget script goes to frame 2 of a movieclip, on frame 2 of that movieclip timeline the sound resides. I could lose the the timeline could and put in some actionscripting to play the sound instead - I just don't know how to code the mute button so the sound stays off indefinitely.
 
Use a global volume soundObject...

On the first frame of your movie create the soundObject...

var soundOn:Boolean = true;
var globalSound = new Sound(this);

And on this following on/off toggle button, add this...

muteButton.onRelease = function(){
if (soundOn = !soundOn){
globalSound.setVolume(100);
}else{
globalSound.setVolume(0);
}
};

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
I'll give it a shot and let you know if I got it to work within my project.

As always thanks for your help.
 
Can you clarify how I would use this. I put this line of code in the actions layer on root timeline:
var soundOn:Boolean = true;
var globalSound = new Sound(this);

I then labeled the mute button to be: muteButton

and tried put the other code... (muteButton.onRelease = function(){
if (soundOn = !soundOn){
globalSound.setVolume(100);
}else{
globalSound.setVolume(0);
}
}; )

...right in the button and in other places (frame 1 actions layer in root timeline) but it gives me this error:

1067: Implicit coercion of a value of type Untitled_fla:MainTimeline to an unrelated type flash.net:URLRequest.

Can you please clarify where the code should go.

thanks!
 
I am publishing to AS 2.0. I no longer get any errors but the audio still plays after I have clicked the mute button. Not sure if I am using your code correctly though. Does all the code go in frame 1 on root timeline or does this part go right with the button?

I labeled the mute button as muteButton.

muteButton.onRelease = function(){
if (soundOn = !soundOn){
globalSound.setVolume(100);
}else{
globalSound.setVolume(0);
}
};



 
It works!

I put all the code in frame 1 on the root timeline and labeled the mute button muteButton -- published to 2.0 and voila'.

Thanks again for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top