1 Reply Latest reply on Aug 16, 2017 5:39 AM by Colin Holgate

    Canvas: Javascript to stop() a Movieclip not working

    koljae74221351 Level 1

      Dear Community,

       

      the following behavior is not clear to me. Can you please explain the following to me. Please look at this example:

       

      (lib.ClickWidget = function(mode,startPosition,loop) {
          this.initialize(mode,startPosition,loop,{});
      
          // timeline functions:
          this.frame_0 = function() {
              //does not work
              this.f_interactionButtonBackground.stop();
              
              //does work
              self = this
              setTimeout(function(){ self.f_interactionButtonBackground.stop(); }, 1);
          }
          // actions tween:
          this.timeline.addTween(cjs.Tween.get(this).call(this.frame_0).wait(1));
      
          // Layer 3
          this.f_interactionButtonBackground = new lib.interactionButtonBackground();
          this.f_interactionButtonBackground.parent = this;
          this.f_interactionButtonBackground.setTransform(0,0.8);
      
          this.timeline.addTween(cjs.Tween.get(this.f_interactionButtonBackground).wait(1));
      
      }).prototype = getMCSymbolPrototype(lib.ClickWidget, new cjs.Rect
      
      
      
      
      angle(-91,-11.7,261.1,100.7), nul
      

       

      Please compare line 7 and 11. Code in Line 7 does not work but code in line 11 does work. I see that the call to stop() does not result in an error so this.f_interactionButtonBackground does resolve.

       

      What I can imagine is that stop is actually called but just because of some reason only later the move clip will start and the stop is irrelevant calling it before the movieclip actually started. Now adding 1 millisecond it gives enough time so the this.f_interactionButtonBackground started playing and stop is actually stopping it.

       

      Can somebody please say what is happening, because I am afraid that why I am doing is not the right way and not a robust way to solve the problem.

       

      Thanks

        • 1. Re: Canvas: Javascript to stop() a Movieclip not working
          Colin Holgate MVP & Adobe Community Professional

          At the time that line 7 runs the movieclip f_interactionButtonBackground isn't yet intialized, and so after you have told it to stop(), it then tells itself to play(). The initializing within the movieclip doesn't know that you had tried to stop it.

           

          The setTimeout works around that, it runs as soon as it can, and that is already after f_interactionButtonBackground has initialized, and so the trick works.

           

          A safer solution might be to put this into f_interactionButtonBackground's timeline's first frame:

           

          this.stop();

           

          then it will stop itself immediately.