1

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Vishwa Iyer
  • 841
  • 5
  • 14
  • 33

2 Answers2

4

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);
}
Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66
  • my movieClip is called container, and I used container for movieClip in the code above, and the color isn't changing at all (it's still white). – Vishwa Iyer Dec 11 '13 at 16:44
0

Well, you can try and use TweenLite to tween the colors, but that is expensive in memory terms.

Or, you can try this "hack" (never tried, so I don't the result) - create two sprites that will cover the screen, the top one white, under it - the black one. Set the alpha of the black to 0, and the white 1. Then, in ENTER_FRAME gradually reduce the alpha of the white and increase the alpha of black until black has alpha 1. It should produce something similar of that you want...

GeorgeCross
  • 359
  • 3
  • 15