4 Replies Latest reply on Oct 7, 2009 10:21 PM by DraconianDevil

    Problem in Controlling sounds induvidually through AS2

    DraconianDevil Level 1

      Hi There, I am a newbie who is trying to learn Flash by myself. I am pretty good with the stuff, I have recently started learning loading sounds with Action Scripts..


      Recently, I saw a flash file where there are four horses, and you click on each horse to make them sing. you click on them again to make them stop. this way, you can mix the sounds to get different outputs each time. here is the link to the file: Horses.swf


      I tried to make my own version of the horses.. So I started to learn all the action scripts required (that I could find!) and started making the flash animation.


      With much difficulty, I figured out how to toggle the sounds on and off with a single buttons, and to play different songs for different buttons. But now, I am stuck with this bit. Here is my problem:


      I can click on any button to play one sound, while the sound is playing, I can click on other button, and the different sound plays just like it should. However, when I click on any button to stop that particular sound, ALL Sounds stops immediately. Here is the link to the file that I programmed:myOwnHorses.swf


      I have even attached the source file that I am working on.. Please let me know What I am doing incorrectly!


      Thank you very much!


      ** Additional Info **


      I have declared the sound variables in the first frame of _root


      the code in the root layer is:


      var boy1 = 1;
      mySound1 = new Sound(this);


      var boy2 = 1;
      mySound2 = new Sound(this);


      var girl1 = 1;
      mySound3 = new Sound(this);

      And, There are three buttons (as you can see in the link above - My own horses . swf ) and with the click of each button, I am checking to see if the sound is already playing, and if it is playing, I am stopping the sound.


      Button 1:


      on (press) {
      if (_root.boy1 == 1) {
        _root.boy1 = 0;
      } else if (_root.boy1 == 0) {
        _root.boy1 = 1;


      Button 2:


      on (press) {
      if (_root.girl1 == 1) {
        _root.girl1 = 0;
      } else if (_root.girl1 == 0) {
        _root.girl1 = 1;


      Button 3:


      on (press) {
      if (_root.boy2 == 1) {
        _root.boy2 = 0;
      } else if (_root.boy2 == 0) {
        _root.boy2 = 1;



      If you have any doubts, please let me know, I will clarify to the best of my knowledge!

      please help me out with this guys! thanks a lot again!

        • 1. Re: Problem in Controlling sounds induvidually through AS2
          clbeech Level 3

          very good it looks like you're getting going just fine - good job!


          you're issue here is like to do with declaring the 'scope' of the Sound object within the constructor - this is often a 'good' thing to do  - so good work, however what this does is creates a 'global' object that controls 'any' sound within the scope designated.  since you have declared all of them to be within the scope of 'this' any of the three sounds will 'control' *all* sound objects running within the scope targeted.  simply remove the 'this' from each and you should then have individual control of them.

          • 2. Re: Problem in Controlling sounds induvidually through AS2
            DraconianDevil Level 1

            Hello Clbeech!

            Firstly, Thank you very much for appreciating my shabby work!


            I did as you recomend - I fired the 'this' keyword in the constructor.

            now, the code part in the decleration is like this:


            mySound1 = new Sound();


            similarly, I updated the other variables too. [ previously it was " mySound1 = new Sound(this); " ]


            But I am still stuck with the same problem! when I click on any other buttons, all sound still stops! may be it would help if you could look at the source file? I realized that I had not attached the source file, so here is the link: Source File.


            Thank you very much again!

            • 3. Re: Problem in Controlling sounds induvidually through AS2
              DraconianDevil Level 1

              Any updates on this anyone?


              or Am I doing it in a wrong way?


              I mean, is there any other way to do this?

              • 4. Re: Problem in Controlling sounds induvidually through AS2
                DraconianDevil Level 1

                okay I did a little trial and error, tried to declare the sound object in several places and finally found out a way to make them work perfectly!!


                first, I had to create a movie clip, and code all the lines inside that movie clip,

                and while declaring the sound object, initialize the object with 'this' constructor. so the sound object is not stuck to the movie clip.


                from then on, it never interrupts any other sounds anywhere else in the movie. I had to write a lil extra lines to make the sound stop and play with the click of same movie clip, but, in the end, i got it to work!!


                thanks a lot for helping me out CLBEECH. your hint on constructors really did the trick, I dint realize what I was passing the 'this' operator till you told me!

                did a lil trial and error and bent it to my will, finally!


                thanks very much again!