Flash Sound and Volume part 3

esse quam videri
Revision as of 03:23, 9 February 2016 by Jeff (talk | contribs) (Text replacement - "syntaxhighlight lang="csharp" line="1" " to "syntaxhighlight lang="csharp"")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Flash Add Volume up and Volume Down

Draw something for an Volume Up button and a Volume Down Button

my buttons look like this

FlashVol AllButtons.png

call the Volume up button 'btnUp' and the Volume Down button btnDown. Don't forget to name the instance.

btnUp.onRelease = function() {
    //Set the volume equal to the current volume + 5 or 100 whichever is less (don't let the volume go higher than 100)
    mySound.setVolume( Math.min((mySound.getVolume() + 5) , 100));
};
btnDown.onRelease = function() {
    //Set the volume equal to the current volume  -5 or 0 whichever is more (don't let the volume go lower than 0)
        mySound.setVolume( Math.max((mySound.getVolume() - 5), 0));
};


Code for key presses

//Do this on Every Frame
this.onEnterFrame = function() {
	if(Key.isDown(Key.RIGHT)){ //Right Key is Pressed
		//Play the sound 1000 times
		mySound.start(0,1000); 
	}
	
	if(Key.isDown(Key.LEFT)){ //Left Key is Pressed
		//Play the sound 1000 times
		mySound.stop(); 
	}
	
        if(Key.isDown(Key.UP)){ //Down Key is Pressed
	 	//Set the volume equal to the current volume + 5 or 100 whichever is less (don't let the volume go higher than 100)
                mySound.setVolume( Math.min((mySound.getVolume() + 5) , 100));
	}
	
        if(Key.isDown(Key.DOWN)){ //Down Key is Pressed
		//Set the volume equal to the current volume  -5 or 0 whichever is more (don't let the volume go lower than 0)
                mySound.setVolume( Math.max((mySound.getVolume() - 5), 0));
	}
};

Code to Change Sounds

soundOne.onRelease = function() {
	    mySound.stop(); 
		mySound.attachSound("song_one"); 
		mySound.start(0,1000); 
}

soundTwo.onRelease = function() {
	    mySound.stop(); 
		mySound.attachSound("song_two"); 
		mySound.start(0,1000); 
}

Complete Code for Multi Song Player

mySound = new Sound();                  //New sound object called mySound
mySound.attachSound("song_one");    //set mySound = to the named instance in the library
btnPlay.onRelease = function() {
    //Play the sound 1000 times
    mySound.start(0,1000); 
};
btnStop.onRelease = function() {
    //Stop playing the sound
    mySound.stop(); 
};
btnUp.onRelease = function() {
    //Set the volume equal to the current volume + 5 or 100 whichever is less (don't let the volume go higher than 100)
    mySound.setVolume( Math.min((mySound.getVolume() + 5) , 100));
};
btnDown.onRelease = function() {
    //Set the volume equal to the current volume  -5 or 0 whichever is more (don't let the volume go lower than 0)
        mySound.setVolume( Math.max((mySound.getVolume() - 5), 0));
};

song_one_btn.onRelease = function() {
	    mySound.stop(); 
		mySound.attachSound("song_one"); 
		mySound.start(0,1000); 
}

song_two_btn.onRelease = function() {
	    mySound.stop(); 
		mySound.attachSound("song_two"); 
		mySound.start(0,1000); 
}

Final Files

link to final swf

http://iam.colum.edu/si/FlashVolume/FlashVolume.swf - source files

http://iam.colum.edu/si/FlashVolumePause/FlashVolumePause.swf - source files