Help me sort this out, and I’ll credit you as a collaborator (if you want, I can understand if you wouldn’t want to be associated with the game in question :P). The problem I’m having is now one-fold:
1) Turning music off also turns off all sounds, despite the movie clips having nothing in common. Whereas the music button directly deactivates the background music, the sound button toggles a Boolean that controls whether sounds get attached in the first place. Thus, the reason they are interfering is a total mystery to me.
Here is the code (I’m up to AS2 now, as soon as possible I shall join all you proper developers in the brave new world that is AS3, polluting its name):
Music Controlling MovieClip
class MusicOn extends MovieClip
{
function onLoad()
{
_root.backGroundMusic = new Sound();
_root.backGroundMusic.attachSound("backgroundloop");
if(_global.numTracksPlaying == undefined)
{
_global.numTracksPlaying = 0;
}
if(_global.musicOff == undefined)
{
_global.musicOff = false;
}
}
function onEnterFrame()
{
this.onRelease = function()
{
if(_global.musicOff == false)
{
_global.musicOff = true;
}else{
_global.musicOff = false;
}
}
if(_global.musicOff == false)
{
this.gotoAndStop(1);
}else{
this.gotoAndStop(2);
}
if(_global.musicOff == true)
{
_root.backGroundMusic.stop();
_global.numTracksPlaying = 0;
}else{
if(_global.numTracksPlaying == 0) //stops tracks overlapping.
{
_root.backGroundMusic.start(0, 1000);
_global.numTracksPlaying +=1;
}
}
}
}
Sound Controlling MovieClip
class SoundOn extends MovieClip
{
var soundOff:Boolean;
function onLoad()
{
_root.heroSoundFX = new Sound();
_root.yellowBeanSoundFX = new Sound();
_root.greenBeanSoundFX = new Sound();
_root.mudBeanSoundFX = new Sound();
_root.iceBeanSoundFX = new Sound();
_root.whiteBeanSoundFX = new Sound();
_root.blackBeanSoundFX = new Sound();
_root.spikeBeanSoundFX = new Sound();
_root.redBeanSoundFX = new Sound();
_root.blueBeanSoundFX = new Sound();
_root.laserBeanSoundFX = new Sound();
}
function onEnterFrame()
{
this.onRelease = function()
{
if(soundOff != true)
{
soundOff = true;
this.gotoAndStop(2);
}else{
soundOff = false;
this.gotoAndStop(1);
}
}
}
}
Example of how the Sound code works inside the MovieClip
if(_root.soundOn.soundOff != true)//MovieClip instance name is soundOn
{
_root.yellowBeanSoundFX.attachSound("GetYellowbean");
_root.yellowBeanSoundFX.start();
}
Thanks for any help you can give, the last time I posted here you guys got me out of a real dead end.
EDIT:Some of the underscores have mysteriously vanished. Trust me, they were there.