Music Volume that Automatically Lowers?

  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

Hi!

If anyone can help me it would be greatly appreciated! I'm working with Flash MX 2004 and I'm trying to lower the volume, at a specific time, of an mp3 that is playing during my flash movie. The 'music.mp3' begins playing at the start of the movie, then at one point, another sound effect of something falling and going boom ('boom.wav') plays but I can hardly hear it over the music. So I was wondering if there is a simple process to make it so that at the point the sound effect 'boom.wav' plays, the 'music.mp3' volume decreases enough, say down to 25% of the original volume or something, so that I can hear the 'boom.wav' effect. Is this a possibility?

Also, I'm not totally sure if I'm equipping (I guess that term works?) the sound files properly in my movie. Maybe someone can explain if the following way i got it to work is okay, or if there is a more solid way to do it. Here are the steps of how I got it to work:

1. Import 'music.mp3' into the library.
2. Create a new layer exclusively for 'music.mp3'.
3. Create a keyframe on that layer.
4. Go down to the Properties menu at the bottom of the screen and under sound, select 'music.mp3' from the dropdown menu.

This is also the way I installed the 'boom.wav' effect as well (except on a separate layer). Any help would be unbelievably helpful!

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

By using Sound() objects you have more control over your sound.

There are a few threads in this section already dealing with Sound() objects. And I always personally recommend reading up at http://www.kennybellew.com/tutorial It's the best Sound() objects tutorial you will find on the web.
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

Thanks for the help!
Okay i read up on Sound() objects at http://www.kennybellew.com/tutorial/ and i found this thread which was helpful http://www.ozzu.com/flash-forum/need-help-putting-seamless-sound-backgrd-swf-t48116.html.

However, i didnt see anything that explains how to have a sound to automatically lower its volume at certain points in the movie. i could see how a button clicked might be able to do that - whatever.setVolume(10);, ? but thats not what i want.

Is there anything that works like: song plays automatically when movie starts at volume(100), at frame 400 song plays at volume(10), then if i want fades out at frame 600.

if i cant figure this out through actionscripts, my other idea was to import the audio file into an audio editing program and try to lower the volumes at the right times. then save it as a new file and import it into flash like that. i think this would work but i have a feeling it would take a *plum* load of trial and error and im also concerned about losing audio quality.

i hope someone can please help.
thanks again!
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

you don't need to call all actions on a button command, if you put whatever.setVolume(10); on the frame itself (right click on the frame and open the actions panel) the action will get called when that frame is it.

And for a fade out on frame 600 I would recommend doing something like storing the volume value in a variable (lets call it soundVolume for thie example) then on frame 600 do something like
Code: [ Select ]
var soundVolume = 10;
this.onEnterFrame = function(){
if (soundVolume>0){
  soundVolume--
  whatever.setVolume(soundVolume);
} else {
  delete this.onEnterFrame;
  whatever.stop();
}
}
  1. var soundVolume = 10;
  2. this.onEnterFrame = function(){
  3. if (soundVolume>0){
  4.   soundVolume--
  5.   whatever.setVolume(soundVolume);
  6. } else {
  7.   delete this.onEnterFrame;
  8.   whatever.stop();
  9. }
  10. }
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

Wow you're amazing! it worked! thanks so much! ive almost got exactly what im trying to do. The code for the fade out worked great, now I was wondering how to fade the music back in again without stopping it. i tried the below code at one frame to quiet the music without stopping it:

var soundVolume = 100;
this.onEnterFrame = function(){
if (soundVolume>15){
soundVolume--
music.setVolume(soundVolume);
} else {
delete this.onEnterFrame;
}
}


The above worked. Then at a later frame i tried reversing the code but it did not work and the music just kept playing at volume15 and didn’t increase back up to 100:


var soundVolume = 15;
this.onEnterFrame = function(){
if (soundVolume>100){
soundVolume--
music.setVolume(soundVolume);
} else {
delete this.onEnterFrame;
}
}


Also, i was wondering if it is possible to control the speed at which the sound fades in and out? Can it fade faster? I feel so unbelievably grateful that you’re taking the time to answer my questions! You’re the man!
Thanks!
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

One last thing. i just noticed that when the music is set to volume15, all the other sound files that are playing simultaneously are also set to volume15. i want the music to be at vol15, but the other sound effects to be at 100, or whatever level i chose. i hope im not bugging you too much, so im going to check through the kennybellew sound tutorial again to see if he knows a solution.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Your problem is because soundVolume is never greater than 100 (as per what your if statement is checking) and you are still decrementing it.

Code: [ Select ]
var soundVolume = 15;
this.onEnterFrame = function(){
  if (soundVolume<100){
    soundVolume++
    music.setVolume(soundVolume);
  } else {
    delete this.onEnterFrame;
  }
}
  1. var soundVolume = 15;
  2. this.onEnterFrame = function(){
  3.   if (soundVolume<100){
  4.     soundVolume++
  5.     music.setVolume(soundVolume);
  6.   } else {
  7.     delete this.onEnterFrame;
  8.   }
  9. }


Now for the faster fading soundVolume++ and soundVolume-- are incrementing and decrementing (respectively).

soundVolume++ is the same as soundVolume = soundVolume+1 or soundVolume += 1.

soundVolume-- is the same as soundVolume = soundVolume-1 or soundVolume -= 1.

If you use soundVolume += or soundVolume -= you can put in a higher value than 1 for a faster incrementation or decrementation.

And now for all sound being turned down. Erm.. this may be because your Sound Object doesn't target anything specific. Here is the part of the tutorial that goes over controlling individual sounds...

http://www.kennybellew.com/tutorial/independent.htm
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

Heres what i tried and its not working for some reason:

1. Started a brand new flash doc
2. imported 2 sound files – music.mp3, and boom.wav
3. right clicked music.mp3 file in the library > linkage > Identifier = music > check export for ActionScript
4. right clicked boom.mp3 file in the library > linkage > Identifier = boom > check export for ActionScript
5. created two new layers on the root timeline: one named ‘sound objects’, the other named ‘actions’
6. made each layer 60 frames long
7. at frame 60 on the actions layer, created a keyframe and assigned the action stop

*Okay i think this is where things get screwed up!

8. created a movie clip: Insert > New Symbol > name: musicMc > behavior: Movie clip > OK
9. created a movie clip: Insert > New Symbol > name: boomMc > behavior: Movie clip > OK
10. after hitting OK, im now in the edit movie clip area (or whatever you call it), so i click scene1 at the top above the timeline to go back to the root timeline.
11. on the root timeline, on frame1 of the layer named ‘sound objects’, i drag the movie clip musicMc onto the stage (a small icon of a black circle with a cross through it shows up)
12. on the root timeline, on frame30 of the layer named ‘sound objects’ i inserted a keyframe, then drag the movie clip boomMc onto the stage (a small icon of a black circle with a cross through it shows up)
13. on the root timeline, i clicked once on frame 1 of the layer ‘sound objects’ (where musicMc movie clip is), then opened the actions menu and inserted this:
firstSound = new Sound(musicMc);
firstSound.attachSound("music");
firstSound.setVolume(20);
firstSound.start(0, 1);
14. on the root timeline, i clicked once on frame 30 of the layer ‘sound objects’ (where boomMc movie clip is), then opened the actions menu and inserted this:
secondSound = new Sound(boomMc);
secondSound.attachSound("boom");
secondSound.setVolume(100);
secondSound.start(0, 1);
15. I hit Ctrl+Enter to Test the movie and... it successfully plays music.mp3 at volume20 until it reaches frame30 when suddenly the boom.wav plays at volume100, however this somehow triggers music.mp3 to jump up to volume100 as well sounding load and retarded!
My goal is to make it so that at frame30 when boom.wav plays at volume100, music.mp3 stays at volume20. I know this must be possible - i have faith!


Thanks for all your help!!
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

by the way, the fading in and out and the soundvolume options you suggested worked perfectly! Thanks! Now i think im down to my last challenge (the above post)
  • nickadocker
  • Novice
  • Novice
  • nickadocker
  • Posts: 23

Post 3+ Months Ago

I was offered advice from someone else who suggested this script, which is NOT what i want but here it is for reference:

Code: [ Select ]
_root.createEmptyMovieClip("empty1", _root.getNextHighestDepth());
_root.createEmptyMovieClip("empty2", _root.getNextHighestDepth());
var myAudio_1:Sound = new Sound(empty1);
var myAudio_2:Sound = new Sound(empty2);
myAudio_1.onLoad = function() {
   this.start();
};
myAudio_1.loadSound("speech4.mp3", false);
myAudio_2.onLoad = function() {
   this.start();
};
myAudio_2.loadSound("track06.mp3", false);
var x:Number = 0;
var y:Number = 100;
_root.onEnterFrame = function() {
   x += 1;
   myAudio_2.setVolume(x);
   trace(x);
   if (x>=100) {
     x = 100;
     y -= 1;
     myAudio_1.setVolume(y);
     if (y<=0) {
        delete _root.onEnterFrame;
     }
   }
};
  1. _root.createEmptyMovieClip("empty1", _root.getNextHighestDepth());
  2. _root.createEmptyMovieClip("empty2", _root.getNextHighestDepth());
  3. var myAudio_1:Sound = new Sound(empty1);
  4. var myAudio_2:Sound = new Sound(empty2);
  5. myAudio_1.onLoad = function() {
  6.    this.start();
  7. };
  8. myAudio_1.loadSound("speech4.mp3", false);
  9. myAudio_2.onLoad = function() {
  10.    this.start();
  11. };
  12. myAudio_2.loadSound("track06.mp3", false);
  13. var x:Number = 0;
  14. var y:Number = 100;
  15. _root.onEnterFrame = function() {
  16.    x += 1;
  17.    myAudio_2.setVolume(x);
  18.    trace(x);
  19.    if (x>=100) {
  20.      x = 100;
  21.      y -= 1;
  22.      myAudio_1.setVolume(y);
  23.      if (y<=0) {
  24.         delete _root.onEnterFrame;
  25.      }
  26.    }
  27. };


The above code seems much more complicated then the code you (lostinbeta) were suggesting and I have a feeling its not the direction I want. I want to understand how to get sound objects to work, for example: how did he get this to work http://www.kennybellew.com/tutorial/independent.htm
if you, or someone, could write a step by step process of how to get this code to work from starting with a new document in flash, that would be totally awesome! i know i wouldn't be the only one benefiting from that! again, my goal is to make it so that at frame30 when boom.wav plays at volume100, music.mp3 stays at volume20. I want to have independent control over both sounds, and any other sounds i incorporate throughout the entire movie, so at any frame i want i can increase the volume of one sound and simultaneously decrease the volume of another. and i want this done without the viewer having to press any buttons, so it just happens (like when your watching a movie the sound volume just automatically changes). I hope there is still more help out there for me! and thanks again lostinbeta, you are a huge contribution to this site!

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.