0

I would like to fade in and out and object with the colorTransform-method.

When I apply the colorTransform to my object it does fade out the thing but not fade in. At first I set the alpha of the bitmapData to 0 (for the fade in-effect). After applying the colorTransform it does nothing. No fade in. Otherwise when I set the alpha of the bitmapData to 100 and let it fade out it works.

I don't know where the error might be so is there anyone who might help me with this problem? Or do you know another method for achieving the same goal? Thank you very much for your help.

BTW: My object (tempScore) is no display object. It is blitted onto a canvas.

This is the function that shall colorTransform my object:

private function setAlpha(setMode:int, bmd:BitmapData):BitmapData
{
var rec:Rectangle = new Rectangle(0, 0, bmd.width, bmd.height);
var ct:ColorTransform = new ColorTransform();

if (setMode == 1) {
    ct.alphaMultiplier = .95;
} else if (setMode == 2) {
    ct.alphaMultiplier = 1.05;
} else if (setMode == 3) {
    ct.alphaMultiplier = 0;
} else if (setMode == 4) {
    ct.alphaMultiplier = .5;
} else if (setMode == 5) {
    ct.alphaMultiplier = 1;
}

bmd.colorTransform(rec, ct);
return bmd;
}

This is the code where I'd like to change the alpha but the fade in doesn't work:

setAlpha(2, tempScore.bitmapData);

This is the code where I set the alpha of the bitmapData to 0:

rec = new Rectangle(0, 0, $textWidth, $textHeight);
ct = new ColorTransform();
ct.alphaMultiplier = 0;

tempScore.bitmapData.colorTransform(rec, ct);

1 Answer 1

2

Filters applied to a BitmapData are "destructive", if you let its alpha go down to zero you will loose all image information along with it, so there's nothing to fade back in.

Apply a filter to the Bitmap container displaying the BitmapData instead.

Sign up to request clarification or add additional context in comments.

2 Comments

OMG! Thank you very much. I didn't know that. Are there any non-destructive filters for the bitmapData available?
Problem solved. I used TweenLite and changed the object. Now it's a sprite. With TweenLite it's working now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.