fadeOut a MovieClip in as2

Posted by Vineela | Uncategorized | Tuesday 21 October 2008 3:17 am

The below code shows how to fadeOut a MovieClip


function fadeOut (mc:MovieClip, speed:Number):Void  {
    mc.onEnterFrame = function() {
        if (mc._alpha>=0) {
            mc._alpha -= speed;
        } else {
            delete mc.onEnterFrame;
        }
    };
};

fadeOut(myMovieClipInstance, 5);

You can also declare the same as protoType


MovieClip.prototype.fadeOut = function(speed:Number):Void  {
    this.onEnterFrame = function() {
        if (this._alpha>=0) {
            this._alpha -= speed;
        } else {
            delete this.onEnterFrame;
        }
    };
};

myMovieClipInstance.clip_mc.fadeOut(5);