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);