1 Reply Latest reply on Jan 6, 2012 10:06 AM by Ned Murphy

    animation start/stop/pause on mouseclick #2

    benderrrrrr

      Hi,

      Sorry for opening a new thread -- it was probably unwise to mark my previous question "answered" and then to post a follow-up question in the very same thread and hoping for more help..

       

      My final goal would be to have the animation pause after the first click, then resume with the next click and so on.

       

      So, after successfully having started the animation on click thanks to kglad's advice, I tried adding a

       

      this.addEventListener(MouseEvent.CLICK,stopF);

      function stopF(e:MouseEvent):void{

      this.stop();

      }

       

      in order to make the animation stop on the click thereafter. This did not work when I put it all on the first frame:

       

      stop();

      this.addEventListener(MouseEvent.CLICK,playF);

      function playF(e:MouseEvent):void{

      this.play();

      }

      this.addEventListener(MouseEvent.CLICK,stopF);

      function stopF(e:MouseEvent):void{

      this.stop();

      }

       

      However, in the meantime I found out that if I put the "stop" event handler on the next frame, it stops again on the second click, as wanted. I then assumed I would be able to put a "play" event handler on frame 3 and so forth, in order to create a "pause" workaround.

      Suprisingly, the animation coul not be resumed on the third frame. Why is that? Any chance to have a "pause" functionality on click?

       

      Thanks again!

       

      PS: Here is my "code" in detail:

      on keyframe1 I have:

       

      stop();

      this.addEventListener(MouseEvent.CLICK,playF);

      function playF(e:MouseEvent):void{

      this.play();

      }

       

      Works! Then on keyframe 2:

       

      this.addEventListener(MouseEvent.CLICK,stopF);

      function stopF(e:MouseEvent):void{

      this.stop();

      }

       

      Works! But on keyframe 3: 

      this.addEventListener(MouseEvent.CLICK,playF);

      function playF(e:MouseEvent):void{

      this.play();

      }

       

      does not work!?

        • 1. Re: animation start/stop/pause on mouseclick #2
          Ned Murphy Adobe Community Professional & MVP

          If you have new questions you are better off starting a new posting, even if they followup on something that was solved.  Postings with 0 replies get noticed.

           

          Just create a variable that you toggle each time you click and use that variable to determine whether to stop or play... in frame 1...

           

          stop();

           

          var stopped:Boolean = true;

           

          this.addEventListener(MouseEvent.CLICK,playF);

          function playF(e:MouseEvent):void{

             if(stopped){

                 this.play();

             } else {

                 this.stop()

             }

             stopped = !stopped;

          }