Search code examples
flashactionscriptactionscript-2

AS2 Fade - Transparent to Black


Trying to fade out movie clip object in Action Script 2.

It appears to only work when the movie clip keyframe starts at frame 1. If there are empty frames before it, it doesn't work. How can I change the code so this isn't an issue?

function FadeOut(Clip:MovieClip, Velocidad:Number) {    
Clip.onEnterFrame = function () {
    if (Clip._alpha > 0) {
        Clip._alpha -= Velocidad;;
    } else {
        this.onEnterFrame = null;
        this.FadeOutEnd();
    }
}
}

FadeOut(outr, 5);

Any ideas? Thanks!


Solution

  • I'll try to explain what happens by using an example.

    I had 2 clips in my root, for the 1st one, clp1, my first key frame is the frame 1, when I do FadeOut(clp1, 5), this worked very well and It took 20 frames ( 100 / 5 = 20 ) or 20 iterations of Clip.onEnterFrame, for my second clip, clp2, my first key frame is the frame 20, so here I didn't see anything, why ? Our FadeOut() function can do all it's work in 20 frames, so at the frame 20 of our clp2, FadeOut() has already finished, so we will get our clp2 with alpha = 100. So, to do what you want, we should do on onEnterFrame a clp2.gotoAndStop(20) to see all (100%) the fading effect. Of course, if our first key frame was 5, for example, we will see only 75% of our fading effect.

    I hope that my explanations are clear and help you to get what you want.

    EDIT :

    I think using this.gotoAndStop(this._framesloaded) can do what you want, try it and tel me what do you think.

    function FadeOut(Clip:MovieClip, Velocidad:Number) { 
    
        Clip.onEnterFrame = function () {
    
            this.gotoAndStop(this._framesloaded)
    
            if (this._alpha > 0) {
                this._alpha -= Velocidad
            } else {
                delete this.onEnterFrame // it's the same as : this.onEnterFrame = null
                //this.FadeOutEnd()
            }
        }
    
    }
    
    FadeOut(clp_01, 5);