Music turns off Sound[Solved]

Subscribe to Music turns off Sound[Solved] 5 posts

Sign in to reply


 
avatar for Jaywalker2 Jaywalker2 692 posts
Flag Post

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.

 
avatar for Draco18s Draco18s 5885 posts
Flag Post

To fix your underscore problem:

LEAVE A BLANK LINE BETWEEN YOUR TEXT AND YOUR OPENING <PRE> TAG.

 
avatar for Jaywalker2 Jaywalker2 692 posts
Flag Post

Thanks. Sorry if that’s a common problem.

 
avatar for Moonkey Moonkey 1007 posts
Flag Post

The Sound constructor takes a MovieClip as a parameter. If you don’t specify one, the Sound will control all sounds in the Movie. You should probably create an empty MovieClip for each sound if you want to control them independently.

 
avatar for Jaywalker2 Jaywalker2 692 posts
Flag Post

Ahh, ok – thanks so much!
That’s really helpful…problem solved, with a bit of work.
EDIT:
I actually solved this problem in a different way, in the end: I forgot to specify

_root.backGroundMusic.stop("backgroundloop");

instead of

_root.backGroundMusic.stop();

Silly mistake. Still, always nice to know more about the way Flash builds objects.

Sign in to reply