Skip to main content
Marampazú
Known Participant
December 13, 2017
Answered

Play-Reverse in Animate... work, but...

  • December 13, 2017
  • 1 reply
  • 1578 views

Hello again.

I'm trying to make a play-reverse animation in Animate.

I based on a code that I found (in fact I think it was around here).

It works, I have this code in frame 1:

this.stop();

var raiz = this;

window.llegue = false;

this.botonRwn.mouseEnabled = false;

window.desactivaAvanzar = function () {

     llegue = false;

     raiz.botonFwd.mouseEnabled = false;

}

window.activaBotones = function () {

     legue = false;

     raiz.botonFwd.mouseEnabled = true;

     raiz.botonRwn.mouseEnabled = true;

}

this.botonFwd.on("click", function () {

     llegue = true;

     var miTimer = createjs.Ticker.on("tick", function () {

          if (llegue) {

               raiz.gotoAndStop(raiz.currentFrame + 1);

          } else {

               createjs.Ticker.off("tick", miTimer);

          };

     });

});

this.botonRwn.on("click", function () {

     llegue = true;

     var miTimer = createjs.Ticker.on("tick", function () {

          if (llegue) {

               raiz.gotoAndStop((raiz.currentFrame + raiz.getDuration() - 1) % raiz.getDuration());

          } else {

               createjs.Ticker.off("tick", miTimer);

          };

     });

});

This works, I can navigate in the animation of a movie clip. However, when I return to the timeline and return to frame 1, the play-reverse animation increases, and this every time I go back to frame 1 (which is finally where I have the code).

I was already reviewing the create js documentation and found what my problem is (but not the solution).

..."on ( type  listener  [scope]  [once=false]  [data]  [useCapture=false] ) Function

Inherited from EventDispatcher: on:173

A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.

This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The wrapper function is returned for use with removeEventListener (or off).

IMPORTANT: To remove a listener added with on, you must pass in the returned wrapper function as the listener, or use remove. Likewise, each time you call on a NEW wrapper function is subscribed, so multiple calls to on with the same params will create multiple listeners."

The problem is that according to how I have done the code I do not find how to avoid duplicate calls (which is finally what happens).

Hopefully you can (as always) help me.

Thank you.

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Put the code you don't want to repeat inside of an if statatement in the first frame, like this:

if (!this.loop)

{

     // code to execute

     this.loop = true;

}

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
December 13, 2017

Put the code you don't want to repeat inside of an if statatement in the first frame, like this:

if (!this.loop)

{

     // code to execute

     this.loop = true;

}