7 Replies Latest reply on May 21, 2009 9:23 AM by kglad

    sound problem

    flashiseasy

      Hello

      I have a playhead that moves across the screen and when it hitTests a movie clip it plays a sound. all is working fine except that it will only work the first time it is played. The playhead is controlled by a button. I am working in Actionscrpt2. Here is the code on the movieclip:

       

      onClipEvent(enterFrame){
          if (!soundStarted &&this.hitTest(_root.playHead)){
                gotoAndPlay("andThree");
      soundStarted=true;
                  _root.soundAnd.stop();
          _root.soundAnd.attachSound("and");
          _root.soundAnd.start();
          onSoundComplete = function() {
        soundStarted=false;

      }

      }

      }

       

      In the begining I was having trouble because the hitTest was playing the sound over and over but the above code sorted that out. I think that the new problem was created by fixing the old one.

      thanks for any help.

      Tina

        • 1. Re: sound problem
          kglad Adobe Community Professional & MVP

          you need to reset soundStarted:

           


          onClipEvent(enterFrame){
              if (this.hitTest(_root.playHead)){

          if(!soundStarted){
                    gotoAndPlay("andThree");
          soundStarted=true;
                      _root.soundAnd.stop();
              _root.soundAnd.attachSound("and");
              _root.soundAnd.start();
              onSoundComplete = function() {
            soundStarted=false;

          }

          } else {

          soundStarted=false;

          }

          }

          }

           


          • 2. Re: sound problem
            flashiseasy Level 1

            Hi kglad.

            thanks for your help. The button controlling the playhead now works more than once, but I have got the old problem back which is that when the playhead hitTest the mc it tries to play it more than once. (I think because it tests it over and over again).

            any ideas

            thanks again

            Tina

            • 3. Re: sound problem
              kglad Adobe Community Professional & MVP

              you must be getting a negative hittest and you sound is still playing.  i'm not sure you want the sound to continue playing when the hittest is negative, but if so, you can use the following to prevent the repeatitive restarts:

               

               

              onClipEvent (enterFrame) {
                   if (this.hitTest(_root.playHead)) {
              
                        if (!soundStarted) {
                             startTime = getTimer();
                             gotoAndPlay("andThree");
                             soundStarted = true;
                             _root.soundAnd.attachSound("and");
                             _root.soundAnd.start();
                             onSoundComplete = function () {
                                  soundStarted = false;
                             };
              
                        } else {
                             if(getTimer()-startTime>_root.soundAnd.duration){
                             soundStarted = false;
                             }
                        }
              
                   }
              
              }
              
              • 4. Re: sound problem
                flashiseasy Level 1

                Hi Again.

                It sorted out playing the sound only once, but now the playhead will only ever play it once. (if I press the button that activates the playhead, it moves along the screen the first time and finds the hittest mc and plays the sound, but if I press the button again the playhead moves across the screen but doesnt play the sound.)

                So I think the conflict is that on the one hand I want the sound to play once when it is on the hittest, but I want to be able to repeat the hittest so that it does play again.

                thanks again for any more suggestions.

                Tina

                • 5. Re: sound problem
                  kglad Adobe Community Professional & MVP

                  if you have several objects with that code, use:

                   

                   

                  onClipEvent (enterFrame) {
                       if (this.hitTest(_root.playHead)) {
                  
                            if (!soundStarted) {
                                 startTime = getTimer();
                                 gotoAndPlay("andThree");
                                 soundStarted = true;
                                 _root.soundAnd.attachSound("and");
                                 _root.soundAnd.start();
                                 duration = _root.soundAnd.duration;
                            } else {
                                 if(getTimer()-startTime>duration){
                                 soundStarted = false;
                                 }
                            }
                  
                       }
                  
                  }
                  
                  • 6. Re: sound problem
                    flashiseasy Level 1

                    thanks for all your help.

                    It is now working fine and all the mcs.

                    I think it would be useful for me to understand why it is working, if you know of any good tutorials that deal with this perhaps you could let me know.

                    thanks again

                    Tina

                    • 7. Re: sound problem
                      kglad Adobe Community Professional & MVP

                      you're welcome.

                       

                      and i don't think that stuff would be covered in a tutorial.  nothing special was used except the duration property of your sound instance and programming logic.