View Full Version : [AS3] Music on/off button bug

no one
03-04-2010, 04:36 AM
I was trying to make a button that will allow you to turn on/off the BG music when you click it but currently, there is a problem:

If I turn the button on and waited for 30 second or more and then click it again, it will start playing the music again without stopping the previous one.

This is the code I used:

import flash.media.Sound;
import flash.media.SoundChannel;

var soundOn:Boolean = false;
var myMusic:music = new music();
var myChannel:SoundChannel;

Music_Btn1.addEventListener(MouseEvent.CLICK,toggl eSound);
Music_Btn1.buttonMode = true;
Music_Btn1.mouseChildren = false;

function toggleSound(e:MouseEvent)
soundOn = false;
Music_Btn1.text.text = "MUSIC OFF";
else // sound is off
myChannel = myMusic.play();
soundOn = true;
Music_Btn1.text.text = "MUSIC ON";


This is the swf in the question:


And just in case you can't spot anything in the script, this is the original flash file:


Any idea what cause the bug?

03-04-2010, 10:07 AM
Must be something wrong with your music class.. I can't spot anything wrong with this code.

no one
03-05-2010, 12:08 AM
If you can't spot anything with that script then this is the original flash file


Do you find anything unusual in it?