Difference between revisions of "Flash Sound and Volume part 3"

esse quam videri
Jump to: navigation, search
(Flash Add Volume up and Volume Down)
m (Text replacement - "<csharp>" to "<syntaxhighlight lang="csharp" line="1" >")
Line 15: Line 15:
 
call the Volume up button 'btnUp' and the Volume Down button btnDown. Don't forget to name the instance.
 
call the Volume up button 'btnUp' and the Volume Down button btnDown. Don't forget to name the instance.
  
<csharp>
+
<syntaxhighlight lang="csharp" line="1" >
 
btnUp.onRelease = function() {
 
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)
 
     //Set the volume equal to the current volume + 5 or 100 whichever is less (don't let the volume go higher than 100)
Line 22: Line 22:
 
</csharp>
 
</csharp>
  
<csharp>
+
<syntaxhighlight lang="csharp" line="1" >
 
btnDown.onRelease = function() {
 
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)
 
     //Set the volume equal to the current volume  -5 or 0 whichever is more (don't let the volume go lower than 0)
Line 31: Line 31:
  
 
Code for key presses
 
Code for key presses
<csharp>
+
<syntaxhighlight lang="csharp" line="1" >
 
//Do this on Every Frame
 
//Do this on Every Frame
 
this.onEnterFrame = function() {
 
this.onEnterFrame = function() {
Line 57: Line 57:
  
 
Code to Change Sounds
 
Code to Change Sounds
<csharp>
+
<syntaxhighlight lang="csharp" line="1" >
  
 
soundOne.onRelease = function() {
 
soundOne.onRelease = function() {
Line 74: Line 74:
  
 
Complete Code for Multi Song Player
 
Complete Code for Multi Song Player
<csharp>
+
<syntaxhighlight lang="csharp" line="1" >
  
 
mySound = new Sound();                  //New sound object called mySound
 
mySound = new Sound();                  //New sound object called mySound

Revision as of 18:28, 25 January 2016

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.

<syntaxhighlight lang="csharp" line="1" > 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));

}; </csharp>

<syntaxhighlight lang="csharp" line="1" > 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));

}; </csharp>


Code for key presses <syntaxhighlight lang="csharp" line="1" > //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));

} }; </csharp>

Code to Change Sounds <syntaxhighlight lang="csharp" line="1" >

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); }

</csharp>

Complete Code for Multi Song Player <syntaxhighlight lang="csharp" line="1" >

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); }

</csharp>

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