CrossFade effect in Flash with AS 3.0
I'm trying to do a crossfade effect, and I have
TransitionManager开发者_Python百科.start(imageHolder, {type:Fade, direction:Transition.IN, duration:0.75});
Which makes the image fade in, but I also want the image to fade out which it doesn't do, when I change direction:Transition.IN to direction:Transition.OUT
Anyone know what I'm missing? Thanks!
Use Greensocks TweenLite. Your life will be better for it. The same line with TweenLite would be:
TweenLite.to(imageHolder, 0.75, {alpha:1});
Then to fadeout you would do:
TweenLite.to(imageHolder, 0.75, {alpha:0});
You could also do this simple fade using a Boolean flag and on enterFrame like this:
var fadeIn:Boolean = true;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(e:Event):void
{
var easeSpeed:Number = 0.4;
var targetAlpha:Number = (fadeIn) ? 1 : 0;
imageHolder.alpha += (1 - imageHolder.alpha) * easeSpeed;
}
just set fadeIn to true or false anywhere else in your code, and the enterframe will take care of the fading. targetAlpha is set using a ternary operator, that check if fadeIn is true or false. If true, then targetAlpha is set to 1, else it's set to 0. The last line in the enterFrameHandler function is a simple ease algorithm, that eases towards the target by a percentage each frame. Adjust the easeSpeed till it looks right.
精彩评论