3 Replies Latest reply on Jan 6, 2012 10:23 AM by kglad

    animation start on mouseclick

    benderrrrrr

      Hi,

      I have a most simple animation which I want to start on mouse click. I use CS5 and ActionScript 3.0. I have one layer where my animation is in, and an actions layer.

       

      When I add a

      stop();

      at frame 1, the whole thing does not start. So far, so good. How do I tell Flash that it should then start the animation after clicking the mouse?

       

      You can find my .fla file at

      http://dl.dropbox.com/u/2481983/stopinserted.fla

       

      I am a complete newbie but have tried since hours to overcome this problem. Would be so great if you could help. 

      Thanks!

        • 1. Re: animation start on mouseclick
          kglad Adobe Community Professional & MVP

          use:

           

          this.addEventListener(MouseEvent.CLICK,playF);

           

          function playF(e:MouseEvent):void{

          this.play();

          }

          • 2. Re: animation start on mouseclick
            benderrrrrr Level 1

            Thanks so much!!!

            This does exactly as I want:

             

            stop();

             

            this.addEventListener(MouseEvent.CLICK,playF);

             

            function playF(e:MouseEvent):void{

            this.play();

            }

             

             

            Now -- why wouldn't it work when I add an analogous "stop" event via:

             

            this.addEventListener(MouseEvent.CLICK,stopF);

             

            function stopF(e:MouseEvent):void{

            this.stop();

            }

             

            to make the animation stop after it has started after the first click?

            (I would love to be able to pause the animation on click after it started, and to resume with another click)?

            • 3. Re: animation start on mouseclick
              kglad Adobe Community Professional & MVP

              because you're executing both the playF() and stopF() functions when the stage is clicked.  whichever executes last will be the only thing one your perceive.

               

              you want to use a toggle.  replace all that code with:

               

               

               

              stop();

               

              this.addEventListener(MouseEvent.CLICK,toggleF);

               

              function toggleF(e:MouseEvent):void{

              if(!this.toggle){

              this.play();

              } else {

              this.stop();

              }

              this.toggle=!this.toggle;

              }