Hello again! I have this Mute/Unmute button for a music.
I have the following code , for when you click the button a first time, do an action (mute music), and then when you hit the button a 2nd time, undo that action (unmute music).
Actionscript Code:
var pressed=false; //tell flash that the button has not been pressed yet
btn.onPress=function(){ //pressing the button for the first time
if(pressed==false){ //if the button has not been pressed yet,
pressed=true; //tell flash the button has been pressed 1st time
this.gotoAndStop(2); //button pressed frame
music.setVolume(0); //mute music
}
else { //if the button has been pressed the 1st time,
music.setVolume(100); //unmute music
pressed=false; //button has been pressed 2nd time
this.gotoAndStop(1); //button released frame
}
That works 100%. Now i want to store these variables in a Shared Object, so when you load the flash the first time, and press the button to mute the music, when you refresh the page, the button remains muted and pressed.
I think the thing goes like this. I create the Shared object variable
Actionscript Code:
var saveState:SharedObject.getLocal ("cookie");
Then in the button code, when muting and unmuting the music and setting pressed=true or pressed=false
Actionscript Code:
btn.onPress=function(){ //pressing the button for the first time
if(pressed==false){ //if the button has not been pressed yet,
pressed=true; //tell flash the button has been pressed 1st time
saveState.data.pressed=pressed; //save
this.gotoAndStop(2); //button pressed frame
music.setVolume(0); //mute music
}
else { //if the button has been pressed the 1st time,
music.setVolume(100); //unmute music
pressed=false; //button has been pressed 2nd time
saveState.data.pressed=pressed; //save
this.gotoAndStop(1); //button released frame
}
and then in the firstframe make an onLoad function to Load the Shared Object automatically
Actionscript Code:
onLoad=function(){
saveState.data.pressed=pressed;
}
But not working. Any help? Thanks