actionscript Code:
stop();
//Variables
nuevoBTN.btnTEXT="nuevo"
loadBTN.btnTEXT="continuar"
clearCache.btnTEXT="borrar cache"
var canLoad:Boolean;
var saveState:SharedObject = SharedObject.getLocal("cookie");
total_lvls = 8;
var globalVolume:Sound = new Sound()
//Functions
//Load saved level
function loadlvl(){
trace("loading lvl");
for(i=1;i<total_lvls+1;i++){
if(saveState.data.rooms == i ){
gotoAndStop("lvl"+i);
}
}
};
function lvlsound(){
trace("This is happening");
newlevel.stop();
newlevel.start(0,1);
};
//Restart level button
function restart(){
reiniciarBTN.onPress=function(){
reiniciar=true;
stopAllSounds();
gotoAndStop(2);
}
};
if(reiniciar==true){
music.stop();
loadlvl();
};
// declare sounds first, so that you may change its volume depending on the saved value
music.attachSound ("music");
music2.attachSound ("music2");
newlevel.attachSound ("newlevel");
music3.attachSound ("music3");
window.attachSound("ventana");
elisa.attachSound("elisa");
success.attachSound("success");
trashing.attachSound("trashing");
failed.attachSound("failed");
broken.attachSound("broken");
broken2.attachSound("broken2");
music = new Sound();
music2 = new Sound();
music3 = new Sound();
newlevel=new Sound();
window=new Sound();
elisa =new Sound();
success=new Sound();
trashing=new Sound();
failed = new Sound
broken=new Sound();
broken2=new Sound();
ventana2=new Sound();
//Music
music.start();
// check if saved value is declared/created
if(saveState.data.pressedMut != undefined){
// if yes, then set pressed's value as the saved value
pressedMut = saveState.data.pressedMut;
// execute this function, to execute the same set of code
// by simply calling that function, saves a lot of time and is easy to edit
checkMute();
}
else {
// if not, then set default value as FALSE
pressedMut = false;
checkMute();
};
btn.onPress = function(){
// this changes pressed's value to the opposite, if it's TRUE,
// then it will turn to FALSE, and vice versa
pressedMut = !pressedMut;
saveState.data.pressedMut = pressedMut;
checkMute();
saveState.flush();
};
// the actual function
function checkMute(){
// check if pressed's value is TRUE
if(pressedMut == true){
// if it is, mute sound
btn.gotoAndStop(2);
globalVolume.setVolume(0);
}
else {
// otherwise, unmute sound
btn.gotoAndStop(1);
globalVolume.setVolume(100);
}
};
music.onSoundComplete=function(){
music2.start();
};
music2.onSoundComplete=function(){
music.start();
};
//Buttons
//New game button
nuevoBTN.onPress=function(){
this.gotoAndStop(3);
}
nuevoBTN.onRelease=nuevoBTN.onReleaseOutside=function(){
this.gotoAndStop(2);
music.stop();
music2.stop();
gotoAndStop("lvl1");
reiniciar=false;
}
if(saveState.data.rooms!=undefined){
loadBTN._alpha=100;
canLoad=true;
}
else {
loadBTN._alpha=30;
canLoad=false;
};
nuevoBTN.onRollOver=function(){
this.gotoAndStop(2);
}
nuevoBTN.onRollOut=function(){
this.gotoAndStop(1);
}
//Load button
loadBTN.onPress=function(){
if(canLoad==true){
this.gotoAndStop(3);
}
};
loadBTN.onEnterFrame=function(){
loadBTN.onRelease=loadBTN.onReleaseOutside=function(){
if(canLoad==true){
music.stop();
music2.stop();
loadlvl();
this.gotoAndStop(2);
}
}
loadBTN.onRollOver=function(){
this.gotoAndStop(2);
}
loadBTN.onRollOut=function(){
this.gotoAndStop(1);
}
};
//Clear cache button
clearCache.onPress=function(){
this.gotoAndStop(3);
};
clearCache.onRelease=clearCache.onReleaseOutside=function(){
saveState.clear();
canLoad=false;
loadBTN._alpha=30;
this.gotoAndStop(2);
gotoAndStop(2);
};
clearCache.onRollOver=function(){
this.gotoAndPlay(2);
}
clearCache.onRollOut=function(){
this.gotoAndStop(1);
};