# Buttons don't work in replay

**URL:** https://forum.kirupa.com/t/buttons-dont-work-in-replay/289072
**Category:** Uncategorized
**Created:** [May 26, 2009, 2:37am UTC](https://forum.kirupa.com/t/buttons-dont-work-in-replay/289072 "2009-05-26T02:37:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bousky](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@bousky](https://forum.kirupa.com/u/bousky)
#### Post date: [May 26, 2009, 2:37am UTC](https://forum.kirupa.com/t/buttons-dont-work-in-replay/289072/1 "2009-05-26T02:37:16Z")

</div>

Hi, I just found this forum and after a quick look around I am sure that I can learn plenty here. I am new to actionScript and have much to learn. I am running out of time to solve this problem. I hope someone can help.

I have created a simple little game for a class. It all works perfectly…except that after the first play…after the replay button is clicked the music control buttons, volume up and down, Sound stop and play all stop working. I am afraid I am lost. I think it needs to be fixed in the function playSound()…I just don’t no how to fix it.

I have pasted the code below. I appreciate any help that I can get.

Thank you,  
Michelle

var bool:Boolean

var score: Number = 0;

var flag:Number = 1;

var myTimer:Timer = new Timer(1000);

var soundReq:URLRequest = new URLRequest(“music.mp3”);

var sound:Sound = new Sound();

var soundControl:SoundChannel = new SoundChannel();

var volumeControl:SoundTransform = new SoundTransform();

var flag2:Number = 1;

count\_txt.text = “0”;

myTimer.addEventListener(“timer”, timedFunction);

insect\_btn.visible = false;

timer\_txt.text = “20”;

function disappear(e:MouseEvent):void  
{

```
if (timer_txt.text == "0")
{
    launch_btn.removeEventListener(MouseEvent.CLICK, target);
    insect_btn.removeEventListener(MouseEvent.CLICK, disappear);
}
else
{
    insect_btn.visible = false;           
    count_txt.text = String(++score);
 }

```

}

function target(e:MouseEvent):void  
{  
if(flag==1)  
{  
myTimer.start();  
flag = 0;  
}  
insect\_btn.x = Math.random()\*625;  
insect\_btn.y = Math.random()\*475;  
insect\_btn.visible = true;  
}

function timedFunction(e:TimerEvent)  
{  
var tc:int= 20 - myTimer.currentCount;  
timer\_txt.text = tc.toString();  
if (myTimer.currentCount \>19)  
{  
insect\_btn.removeEventListener(MouseEvent.CLICK, disappear);  
launch\_btn.removeEventListener(MouseEvent.CLICK, target);  
myTimer.stop();  
gotoAndPlay(“done\_frame”);  
}  
}

function playAgain(evt:MouseEvent):void  
{  
gotoAndPlay(“play\_frame”);  
}

if(!bool){  
bool=true;  
sound.load(soundReq);  
soundControl = sound.play();  
}

function playSound(event:MouseEvent):void  
{  
if ( flag2 == 0)  
{  
soundControl = sound.play();  
flag2 = 1;  
}

}

function stopSound(event:MouseEvent):void  
{  
soundControl.stop();  
flag2 = 0;  
}

function increaseVolume(event:MouseEvent):void  
{  
volumeControl.volume += .5;  
soundControl.soundTransform = volumeControl;  
}

function decreaseVolume(event:MouseEvent):void  
{  
volumeControl.volume -= .5;  
if (volumeControl.volume \>= 0)  
soundControl.soundTransform = volumeControl;  
else  
volumeControl.volume = 0;

}

insect\_btn.addEventListener(MouseEvent.CLICK, disappear);  
launch\_btn.addEventListener(MouseEvent.CLICK, target);

btn\_play.addEventListener(MouseEvent.CLICK, playSound);  
btn\_stop.addEventListener(MouseEvent.CLICK, stopSound);

btn\_up.addEventListener(MouseEvent.CLICK, increaseVolume);  
btn\_down.addEventListener(MouseEvent.CLICK, decreaseVolume);
