# Using one button to turn music on/off

**URL:** <https://forum.kirupa.com/t/using-one-button-to-turn-music-on-off/245858>\
**Category:** flash\
**Created:** [December 4, 2007, 10:18pm UTC](https://forum.kirupa.com/t/using-one-button-to-turn-music-on-off/245858 "2007-12-04T22:18:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikedkap](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@mikedkap](https://forum.kirupa.com/u/mikedkap)\
**Post date:** [December 4, 2007, 10:18pm UTC](https://forum.kirupa.com/t/using-one-button-to-turn-music-on-off/245858/1 "2007-12-04T22:18:19Z")

</div>

Is it possible to have one button the toggle my ‘my\_sound.setVolume();’ between 0 and 100.

I’m having a hard time getting the as correct, but here is my idea:

```auto

music_but = "on"
if music_but == "on" {
music_but.onPress = function(){
 my_sound.setVolume(0);
music_but = "off";
}
else if (music_but == "off"){
music_but.onPress = function(){
 my_sound.setVolume(100);
music_but = "on";
};

```

Can anyone help me format this correctly? Thanks!
