Difference between revisions of "Flash Sound and Volume part 3"
esse quam videri
m (Text replacement - "</csharp>" to "</syntaxhighlight>") |
m (Text replacement - "syntaxhighlight lang="csharp" line="1" " to "syntaxhighlight lang="csharp"") |
||
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. | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
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: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
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 | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
//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 | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
soundOne.onRelease = function() { | soundOne.onRelease = function() { | ||
Line 74: | Line 74: | ||
Complete Code for Multi Song Player | Complete Code for Multi Song Player | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
mySound = new Sound(); //New sound object called mySound | mySound = new Sound(); //New sound object called mySound |
Latest revision as of 03:23, 9 February 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
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