Skip to main content
Inspiring
November 25, 2013
Question

Stoping a looping animation code at certain time

  • November 25, 2013
  • 2 replies
  • 423 views

I am using a code which creates a twinkling star effect. I need to make the effect stop at either 30seconds of itplaying or if possible on a certain frame.

Here is the code I am using:

onClipEvent (enterFrame) {

getTargetAlpha = function(){

          return Math.random() * 100;

};

this.speed = 9;

this.target = this.getTargetAlpha();

this.onEnterFrame = function(){

          if(this._alpha < this.target){

                    this._alpha += this.speed;

          }else if(this._alpha > this.target){

                    this._alpha -= this.speed;

          }else if(this._alpha == this.target){

                    this.target = this.getTargetAlpha;

          }

};

}

Is it possible to apply something to achieve this?

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Ned Murphy
Legend
November 25, 2013

You should get any code "on..." objects off of them and keep it all in the timelline.

You can use the setTimeout() function to take care of timing out at 30 seconds and cancelling whatever other code you have processing.  Look it up in the help documentation or search Google for how to use it.

Inspiring
November 25, 2013

Thanks, I will take a look at this function as suggested.