6 Replies Latest reply on Nov 15, 2014 1:51 PM by fillyrboots

    Separate start/stop action for background sound?

    fillyrboots Level 1



      First, let me preface this question with the caveat that I am a complete amateur when it comes to flash and anything I have accomplished thus far is by simply winging it.  Therefore, if my question seems rather inane, there is a good reason why.


      My situation is as follows...


      I am creating a soundboard and would like to have background noise available to loop for the user to activate/stop at any time, and so I would like its activation/stopping action to be separately controlled from the rest of the sounds on the board.


      That is to say that the other sounds on the board are started and stopped via the spacebar, which I have accomplished just fine, but I am running into great difficulty when trying to get the background noise to start and stop with a mouse-click.


      I have created a button for it and attempted to use a 'code snippet' for the start/stop action, but when testing, it starts with the click (like anything else), but stops with the spacebar.


      As I said, I realize this is likely pretty elementary to those well-versed in flash, but I would appreciate any insight into what I might be doing wrong here.


      Thanks very much!

        • 1. Re: Separate start/stop action for background sound?
          robdillon Most Valuable Participant

          From your description it sounds like you are not using sound objects for each of your sounds. You can have 8 sounds playing at any time using sound objects. Each sound can then be independently controlled. The sounds can be imported into the movie, or they can be loaded from a server at runtime.


          A very simple alternative to using sound objects is to place the sounds into their own individual movieClips and play and stop those movieClips. If you are using SoundMixer.stopAll(); that will always stop all sounds from playing, so you don't want to use that.

          • 2. Re: Separate start/stop action for background sound?
            fillyrboots Level 1

            Hi, Rob.


            Thanks very much for your prompt reply. This is when I start to get fuzzy, however, as official flash terms are tossed around, haha.


            Perhaps if I tell you what I've done thus far, you'd get a better idea of what I'd like to do.


            This soundboard has over 100 'buttons', each a separate piece of dialogue. All of those sounds (buttons) are controlled by a 'stop' via spacebar action. All of that works just fine.


            What I would like to do, though, is have a button that activates a loop of background noise (office sounds, in this case) that the user can deactivate at any time by clicking it again. That's where my difficulties are arising.


            In spite of trying to use the code snippet for a mouse-click start/stop for that background noise button, it still gets deactivated by the spacebar. I think perhaps that the sound isn't properly identified in the code and maybe that's why it isn't working. I get confused when looking at the code and seeing the terms I don't fully understand.


            Thanks for the insight about the 8 sounds playing at any time. That means I should fall well within that, as I would, in theory, only ever have one piece of dialogue activate while the background sound is also playing. Do I understand that correctly?


            Thanks again for your help, Rob. I really do appreciate it.

            • 3. Re: Separate start/stop action for background sound?
              robdillon Most Valuable Participant

              It would really help me if I could see your actual movie. It sounds like you are stopping the playback head on the main timeline with your spacebar action. Is that correct? If you can't show me the whole movie, can you show me the code that you are using with the spacebar?

              • 4. Re: Separate start/stop action for background sound?
                fillyrboots Level 1

                Hi again, Rob.


                I'm going to start with a really dumb question, if you don't mind.


                Is anything created in flash considered a 'movie'? I ask because you've asked to see the movie, whereas I just think I'm creating a soundboard. Is a soundboard simply a flash movie in another format, as it were? Sorry for such inane questions, but I like to pick up the correct knowledge and understanding wherever I can.


                As for the code that's controlling the spacebar 'stop' action, here it is. Looking at it again, I do see the 'stop all' portion of it and I know you mentioned that earlier. So I'm wondering how do you create an 'exception', as it were, for the background noise I'd like to control with a mouse-click. Anyway, one thing at a time, I guess. Here's the code:


                stage.addEventListener(KeyboardEvent.KEY_DOWN, spacebarClicked);



                function spacebarClicked(e:KeyboardEvent):void{

                if(e.keyCode == 32) SoundMixer.stopAll();


                Thanks again for your kind attention to my problem, Rob. I really do appreciate it.

                • 5. Re: Separate start/stop action for background sound?
                  robdillon Most Valuable Participant

                  The output from Flash, an .swf file, is commonly called a Flash movie.


                  Using SoundMixer.stopAll(); will always stop all of the sounds that are currently playing. There is no way around that except to not use it. In order to get the flexibility that you want to have, you'll have make your movie more complex. Without actually seeing the file, It's difficult for me to tell you how best to improve what you have.


                  If, for instance, you just have a bunch of sounds and a bunch of buttons to play each sound, you could accomplish this with some relatively simple actionscript.

                  1 person found this helpful
                  • 6. Re: Separate start/stop action for background sound?
                    fillyrboots Level 1

                    Ok, yeah, I'm familiar with the .swf extension now, having made a few soundboards already, so now I know they can be referred to as movies. Thanks!


                    As for this project, it really is just a collection of 'buttons', with each of them being a different sentence or sentence fragment. The spacebar action is handy if you want to stop 'mid-sentence', as it were. So essentially what I'm trying to achieve is to have background sound playing, while still being able to activate/stop the soundboard buttons. In my jumbled head, this means the background sound should follow a different rule than the buttons, yes? I just don't know how to go about doing that properly.


                    So, you say it IS possible to achieve what I'd like to do?


                    edit: I should add, I'm confused when it comes to what a 'sound class' is. In my attempts at trying to do what I'd like to do, I've run into that term and I really don't understand what it means.