2 Replies Latest reply on Jun 4, 2009 7:45 AM by m.angel

    Unsure of codes

    m.angel

      Hi,

      I am struggling with Actionscripting my Flash file-I am still learning Actionscript 2.0 (in Flash CS4). I have tried looking at numerous tutorials but none of them have helped. The code that I have done so far works, but I am unsure how to work out these other problems.
      With my looping sounds, how can I get it to stop playing over the top of itself when it is already playing? Also, I'm not sure on how to get it to stop playing once any of them have been clicked again?
      I have a dog movie clip where the dog needs to jump and bark only when it has been clicked, not sure how to set this up?
      I have a girl movie clip who makes a slurrping sound when the drink is dragged and dropped onto her. But once the drink has been dragged away/clicked again, I need the sound to stop and the drink to go back to the original position.

      Your assistance would be greatly appreciated.

      Below is my code.

       

       

      stop();

      //Attachment of Sounds
      birdSound = new Sound();
      birdSound.attachSound('birds');

      dogbarkingSound = new Sound();
      dogbarkingSound.attachSound('dogbarking');

      slurpingSound = new Sound();
      slurpingSound.attachSound('slurping');

      windSound = new Sound();
      windSound.attachSound('wind');

      laughSound = new Sound();
      laughSound.attachSound('laugh');

       

      //Bird looping sound
      birds_mc.onRollOver = function(){
      if (this._currentframe<=50) {
        birdSound.start(0,999);
      }
      }

       

      //Dog barking looping sound
      dog_mc.onPress = function() {
      if (this._currentframe<=50) {
        //dogbarkingSound.stop();
        dogbarkingSound.start(0,999);
      }
      }


      //Drag and drop drink to girl1 with slurping loop sound
      drink_mc.onPress = function(){
      this.startDrag();
      }

      drink_mc.onRelease = function(){
      stopDrag()
      if (this._droptarget=="/girl1_mc") {
        //slurpingSound.stop();
        slurpingSound.start(0,999);
        trace("slurping")
      }
      }


      //Wind looping sound
      trees_mc.onPress = function() {
      if (this._currentframe<=50) {
        //windSound.stop();
        windSound.start(0,999);
        this.enabled=false;
      }
      };

        • 1. Re: Unsure of codes
          kglad Adobe Community Professional & MVP

          use the stop() method of your sounds.  for example:

           


          stop();

          //Attachment of Sounds
          birdSound = new Sound();
          birdSound.attachSound('birds');

          dogbarkingSound = new Sound();
          dogbarkingSound.attachSound('dogbarking');

          slurpingSound = new Sound();
          slurpingSound.attachSound('slurping');

          windSound = new Sound();
          windSound.attachSound('wind');

          laughSound = new Sound();
          laughSound.attachSound('laugh');

           

          //Bird looping sound
          birds_mc.onRollOver = function(){
          if (this._currentframe<=50) {
            birdSound.start(0,999);
          }
          }

          birds_mc.onRollOut = function(){
            birdSound.stop();

          }

           

          //Dog barking looping sound
          dog_mc.onPress = function() {
          if (this._currentframe<=50) {
            //dogbarkingSound.stop();
            dogbarkingSound.start(0,999);
          }
          }

          dog_mc.onRelease = function() {
            dogbarkingSound.stop();

          }


          //Drag and drop drink to girl1 with slurping loop sound
          drink_mc.onPress = function(){
          this.startDrag();
          }

           

          drink_mc.startX=drink_mc._x;

          drink_mc.startY=drink_mc._y;

           

          drink_mc.onRelease = function(){
          stopDrag()
          if (this._droptarget=="/girl1_mc") {
            //slurpingSound.stop();
            slurpingSound.start(0,999);
            trace("slurping")
          } else {

          this._x = this.startX;

          this._y = this.startY;

          slurpingSound.stop();

          }

          }


          //Wind looping sound
          trees_mc.onPress = function() {
          if (this._currentframe<=50) {
            //windSound.stop();
            windSound.start(0,999);
            this.enabled=false;
          }
          };

          trees_mc.onRelease = function() {
            windSound.stop();

          };
          • 2. Re: Unsure of codes
            m.angel Level 1

            Of course, thank you for that.

            Except, when one sound is playing and it gets clicked on again, it just overlaps-what can I do to fix this problem? The looping sounds don't seem to be looping correctly-could this be because of the way I have set up my stop methods?

            For the dog movie clip, I was advised to put a stop in the first frame of the movieclip and tell it to play when clicked, does this mean that the actionscript for the dog_mc needs to be changed to inside the movie clip, rather than on the maintimeline? Because I have put a stop in the first frame, but now it doesn't jump at all.

            The code for the drink to go back to the original position hasn't worked correctly? She just keeps slurping until you phsyically drag the drink away-but it doesn't automatically go back to the original position.

             

            Any help appreciated.