16 Replies Latest reply on Nov 6, 2007 5:42 PM by jl2000

    sounds setVolume override each other

    jl2000 Level 1
      Hi -
      I have a swf that brings in multiple "child" mcs. The main (parent) timeline has a sound var on it and the children mcs have their sounds. If I set both setVolumes to 100 - no problem. But if I lower the child's sound to 20 - the parent's sound is also lowered.
      What am I doing wrong here? What's the correct way to set this situation up? Ideally I'd like to declare all the sounds in the parent action layer and set all the volumes from one place - but that silenced the child sound. In one experiment, the parent sound got quieter each time I used it after using the child sound.
      What is the "once and for all" way to do this?

      TIA some explanation.
        • 1. Re: sounds setVolume override each other
          clbeech Level 3
          This is because when you do not specify a 'target' Object, calls on the Sound Object act globally. to remedy, add 'this' (or an MC) to the Sound param, to specify it's scope, as in:

          var whoosh_sound:Sound = new Sound(this);

          var radioClick:Sound = new Sound(this);
          • 2. Re: sounds setVolume override each other
            jl2000 Level 1
            clbeech -
            In spite of those changes I still have one setVolume affecting both sounds. Have i implemented this correctly?
            Thanks for the reply.
            • 3. Re: sounds setVolume override each other
              Rothrock Level 5
              To control sounds individually each one must have a different target. Sounds that you want to control together can have the same target.
              • 4. Re: sounds setVolume override each other
                jl2000 Level 1
                Rothrock -
                Thanks for the input.
                Pardon my thickness. Am I using the same target for both sounds?
                • 5. Re: sounds setVolume override each other
                  Rothrock Level 5
                  thick is the new smart!

                  If you put new Sound(this) and both are on the same timeline, then yes. This is a shorthand way of telling flash "this timeline/movieclip" so in that case you would most likely be referring to the main timeline.

                  Generally use createEmptyMovieclip to make as many new clips as sounds i need to control. Something like this:

                  var soundClip1:MovieClip=this.createEmptyMovieclip("soundClip1", 1000)
                  var soundClip2:MovieClip=this.createEmptyMovieclip("soundClip2", 1001)
                  var sound1:Sound=new Sound(soundClip1)
                  var sound2:Sound=new Sound(soundClip2)
                  • 6. Re: sounds setVolume override each other
                    jl2000 Level 1
                    Rothrock -

                    I got this to work but I think I have a lot of duplication of code so I may have misunderstood your suggestion.

                    I put code 1 below on the main/parent timeline, for the whoosh sound that's only used there. Then I have 7 children movie clips that use a different sound - radioClickSnd . In EACH of those I put code 2 below, each time changing the depth and the name of the target empty.

                    As a result there is a setVolume on the parent timeline for one sound, and also on each of the 7 child timelines.
                    If that's what you meant - hey we're good. If I over did it, please fill me in.

                    Thanks for all your help.

                    • 7. Re: sounds setVolume override each other
                      Rothrock Level 5
                      Oh, well, maybe?

                      Actually I didn't know that you already had a bunch of MovieClips. Since they already exist you could use them as the targets for your Sound Instances.

                      Generally when I'm trying to learn something new like this, I put aside my actual project and start with a new, fresh, blank FLA file. I can then learn how to do the new part without all the other distractions. After I figure it out, it becomes much easier to incorporate into my actual project.

                      I would probably do this completely different, but without knowing exactly what you are trying to achieve I'm not exactly sure how to guide you.

                      How many sounds are there?
                      How many sounds might be playing at the exact same time?
                      Why are you trying to control the sound individually?

                      PS: I was just typing that code out of my head. I now notice that it is, of course, createEmptyMovieClip! (Capitalization is important.)

                      • 8. Re: sounds setVolume override each other
                        clbeech Level 3
                        How do :) When I'd stated to use 'this' I was assuming that the Sound Object was being attached to each MC on it's own timeline. Rothrocks, got you on the right track now though.

                        But I would remove the 'targeting' parameter from the 'start()' methods, there are two parameters available here, 1) offsetSeconds and 2) loopNumber, neither of which are to be specified by an MC instance. So I think that the call should be:


                        Also, I'm not certain if this is necessary, but you may want to use the exact names when using 'createEmptyMovieClip();' as in:

                        var www:MovieClip=this.createEmptyMovieclip("www", 1000);

                        Then target the clip:

                        var sound1:Sound=new Sound(www);

                        that should set it up with the correct scope ... I think :)
                        • 9. Re: sounds setVolume override each other
                          jl2000 Level 1
                          Rothrock -
                          Hmmm. You said "Since they (movie clips) already exist you could use them as the targets for your Sound Instances". If you mean that I could put all the sound code for all the children MCs on the parent action layer - that's what I thought when I started - I tried that again ( see the example code 3) but it didn't work. I'd love that to work...it's why I started this thread.

                          There are only 2 sounds; whoosh and radioBtnClick. They are triggered by btn onReleases so are never at the same time. All the occurances of whoosh are on the parent timeline/swf. All the radioBClicks are in the child mcs (from 2 to 5 on each). Never at the same time.

                          If I knew I was this far off I would have started over...but now I really know where everything is.

                          Thanks for your help.
                          • 10. sounds setVolume override each other
                            jl2000 Level 1
                            cbeech -
                            I was wondering about that "snd.start( ??? )" because almost anything I put in there worked. In fact, the messy set up I'm using now "works" but there's emptyMovieClips all over the place ;) Further proof that a little knowledge is dangerous.

                            I appreciate your example of the exact naming. Shheesh am I confused. But your example completes a loop - makes sense. I'll try it.

                            BTW - where DOES "this" fit in?


                            • 11. Re: sounds setVolume override each other
                              Rothrock Level 5
                              Sorry. It looks like I kind of lead you down the wrong path. There is almost never a time when I put code on different timelines, so that is why I wasn't

                              Anyways, here is why I asked those questions. I haven't done a lot with sounds in Flash, but my understanding is they are a bit precious. Isn't it something like you can only control 8 sounds? It has expanded with CS3, but still you can't just make sounds for everything. After a certain point you have to get clever.

                              So if the sounds won't ever be playing at the same time and if they are the same kind of sound, in this case what I would call an interface sound or effect, then I would usually make one clip on my main timeline called something like interfaceSoundClip and one sound that targets that clip, something like interfaceSound.

                              var interfaceSoundClip:MovieClip=this.createEmptyMovieClip("interfaceSoundClip", 1);
                              var interfaceSound:Sound=new Sound(interfaceSoundClip);

                              I would then route all interface sounds (and who knows you might add more later or need to reuse this in a different situation) through that Sound instance. This makes it easier to control all the sounds of a certain kind.

                              If I wasn't happy with the relative volumes of the sound, well first I would probably just break out Audacity and edit the original sound file. But if I needed to control them differently and at different volumes at different times, I would then make a function for playing back the sounds where you could pass the function a linkageID and an optional volume. Something like this:

                              function playInterfaceSound(linkage:String,vol:Number){
                              vol = (vol != undefined) ? vol : 100;

                              Then in all my onReleases, all I would have to do is call this function with whichever sound that button was supposed to make. If I didn't add the second argument the function would just assume full volume.
                              • 12. Re: sounds setVolume override each other
                                clbeech Level 3
                                Rothrock, that's a nice little method there :) like it. I'm not sure what the Sound limits are either, But I have seen some very sophisticated uses, even in AS2, I don't have the link anymore since my computer wnet down and I lost all my bookmarks, but I'd seen an increadible 'mixer' with like, two dozen channels and tempo controls for each, volume, pan you name it, was pretty spiffy. so I don't know how far you can take it, quite aways I guess.

                                @jl: the keyword 'this' is used in reference to the timeline or 'scope' in which the operating Object instance resides, and can sometimes be a little tricky to understand what or where it is referencing, particularly when writing class files. So if the code you are using resides on the timeline of the button instance itself, you could use 'this' to target itself as the MC whose scope you are assigning to the Sound Object. However, Rothrock has it right-er, that it's usually best to write much or all of your code in one place, making it easy to reference, and reducing scope issues, So then you would target the instance name of the MC, and even use the full path to it, if it's deeper that the first level.

                                I was under the impression that you were loading or attaching buttons that contained their own timelines and that the code was being applied there, So I though that using the 'this' keyword would be simple and sufficient.

                                Keep in mind though, that if the instances are being attached to the timeline in some way (like loading) that you cannot target something that does not yet exist, you will need to make sure that the instance is instatiated before targeting the SoundObject. So in this case, if the buttons come and go frequently, it may be best to have their own codes handle their operation, including the attachment of the SoundObject instance(s). However Rothrock's method above, is an excellent way to use a simple call to bring up any sound and adjust the volume at anytime, from anywhere in the doc.
                                • 13. sounds setVolume override each other
                                  jl2000 Level 1
                                  Rothrock -

                                  Thanks - cool function! All the sounds have their own volume setting and they all fire.

                                  At first I had to put all the code on all of the child timelines because the function calls to the main timeline didn't work.

                                  But then I was reading nlbeech's post and the word "path" came up. I've been bitten by that word before. So I started to mess with " _root.playInterfaceSound("radioClickSnd",30);" and finally " _parent.playInterfaceSound("radioClickSnd",30);" worked.

                                  Outstanding. Thanks both of you folks. I really learned something here. (now if only I could remember it ;0)
                                  • 14. Re: sounds setVolume override each other
                                    jl2000 Level 1
                                    clbeech -
                                    Please see my post to Rothrock above and accept my apology for spellng your name wrong.

                                    • 15. Re: sounds setVolume override each other
                                      clbeech Level 3
                                      Hey jlucchesi - you should be able to call Rothrock's awsome method here on the main timeline. Put it in the first frame right, then just make sure that when you call it, you use a reference to the root level (I don't like '_root' much, it can get you into trouble)

                                      _level0.playInterfaceSound('whoosh2', 50);

                                      should work from anywhere :)
                                      • 16. Re: sounds setVolume override each other
                                        jl2000 Level 1
                                        outstanding. Thanks!