Search code examples
actionscript-3flashadobemovieclip

Darkening a movieclip in flash


I have a container movieclip that's white. At the end of my game, I want the movieclip to turn black but gradually, creating an image effect from white to black. Basically I want the movieclip to darken and keep darkening until the movieclip is completely black, and then the darkening stops. Any ideas on how to accomplish this?


Solution

  • You can try a color transform.

    var fade:Number = 1.0;
    var fadeAmount:Number = 0.01;
    var timer:Timer = new Timer(33);
    timer.addEventListener(TimerEvent.TIMER, darken);
    timer.start();
    
    
    function darken(e:TimerEvent):void 
    {
        fade -= fadeAmount;
        if(fade < 0.0) {
            fade = 0.0;
            timer.stop();
        }
        movieClip.transform.colorTransform = new ColorTransform(fade, fade, fade, 1.0, 0, 0, 0, 0);
    }