A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Stoping a looping animation code at certain time

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    23

    Stoping a looping animation code at certain time

    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?

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Solution 1:

    On the movieclip on stage replace your script with this:
    PHP Code:
    onClipEvent (enterFrame

    if(
    _parent._currentframe 40)
    {
    getTargetAlpha = function(){ 
    return 
    Math.random() * 100
    }; 
    this.speed 9this.target this.getTargetAlpha(); 

    if(
    this._alpha this.target)

    this._alpha += this.speed;

    this.speed
    }
    else if(
    this._alpha this.target)

    this._alpha -= this.speed; }else if(this._alpha == this.target)

    this.target this.getTargetAlpha

    }

    Where "40" is the frame you wish to stop the animation.

    Solution 2:

    On your movieclip:
    PHP Code:
    onClipEvent (enterFrame

    if(
    _parent.finished == false)
    {
    getTargetAlpha = function(){ 
    return 
    Math.random() * 100
    }; 
    this.speed 9this.target this.getTargetAlpha(); 

    if(
    this._alpha this.target)

    this._alpha += this.speed;

    this.speed
    }
    else if(
    this._alpha this.target)

    this._alpha -= this.speed; }else if(this._alpha == this.target)

    this.target this.getTargetAlpha

    }

    Name your movieclip "mc" or something and On the first frame of the main timeline:
    PHP Code:
    var finished:Boolean false;

    function 
    delay()
    {
        
    clearInterval(Int);
        
    finished true;
            
    mc._alpha 100;
    }
    var 
    Int setInterval(delay30000); 
    Solution 1 will check for a frame to stop the animation and solution 2 will count to 30 seconds, then stop and set the alpha to 100.

    Hope that helps
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center