This seems like a fairly easy thing to fix but I can’t figure it out…
I’d like to have just one button component in my movie, where you can click it on and off. Also, I’d like it to save a SharedObject so that if the user for example clicks the button to off, the next time they load the movie it will remember to not play the music.
It seems to be working alright, but if the button is set to “on” and then I reload the movie and I click the button to turn the music off, it does not turn it off on the first click. I have to click it TWICE… Not sure why it’s doing that. If I click the button to “off” and then reload it, it works fine when I click the button ONCE to “on”. Here’s the code, I also have a link to the the files.
http://student4www.fullcoll.edu/01210184/mytoki/mytoki.zip
Any help would be much appreciated!
var so:SharedObject = SharedObject.getLocal(“settings”);
var music:Sound = new Sound(new URLRequest(“myMusic.mp3”));
var channel:SoundChannel = new SoundChannel();
music.addEventListener(Event.COMPLETE, musicLoaded);
btn.addEventListener(MouseEvent.CLICK, playSound);
function musicLoaded(e:Event):void {
//check if cookie is set to off; if not, play sound
if (so.data.sounds =="off"){
btn.label = "| off";
channel.stop();
statustxt.text ="stopped";
}
else{
btn.label = "| on";
channel = music.play()
statustxt.text ="playing";
}
}
function playSound(e:MouseEvent) {
SoundMixer.stopAll();
if(btn.selected==true){
btn.label = “| on”;
channel = music.play();
//set cookie to on
so.data.sounds = “on”;
so.flush();
statustxt.text =“playing”;
}
else{
btn.label = “| off”;
SoundMixer.stopAll();
//set cookie here to off
so.data.sounds = “off”;
so.flush();
statustxt.text =“stopped”;
}
}