-
Alpha tween fade in and out AS3
Hello! I'm trying to find the most easiest way to fade in and out a movieclip in AS3. What I did is this:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var myTween:Tween;
TweenOut();
function TweenOut():void
{
myTween = new Tween(text_mc, "alpha", Strong.easeIn, text_mc.alpha, 0, 3, true); myTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinishedHandler);
}
function tweenFinishedHandler(event:TweenEvent):void { myTween = new Tween(text_mc, "alpha", Strong.easeIn, text_mc.alpha, 1, 2, true);
}
But it doesn't give me the result I'm after (it is reversed and starts highlighted then fades out and back highlighted again, should be the other way around. Also I would like to set the number of seconds it stays highlighted before fading out again).
Any ideas?
-
I would suggest using a third party tweening library like tweenlite rather than the built in Tween. It's just so much simpler.
Now, as to why yours fades out rather than in: because you told it to. The fourth parameter in the Tween constructor (text_mc.alpha above) is the beginning value. Assuming you haven't set the alpha otherwise, this will be 1. The next value is the end value. So you are telling it to tween from 1 to 0. That is, from fully opaque to fully transparent. To go the other way, you need to go from 0 to 1.
To add a delay after the first one finishes, start a timer in tweenFinishedHandler. Set a listener on that timer for TIMER_COMPLETE, then kick off the reverse tween in that function.
-
Hi 5TonsOfFlax I tried to change from 0 to 1 instead (the text_mc is fully highlighted as default) didn't work. Can you please show me the whole code with the timer please? I'm a beginner in AS3, thanks.
Last edited by Balthazor; 02-24-2012 at 04:57 PM.
-
Well, I hardly ever deal with Tweens, and never the built in, but I'd have thought this should work:
Code:
var myTween:Tween;
fadeIn();
function fadeIn():void{
myTween = new Tween(text_mc, "alpha", Strong.easeIn, 0, 1, 3, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinishedHandler);
}
var timer:Timer;
function tweenFinishedHandler(event:TweenEvent):void{
timer = new Timer(3000,1); //3 seconds, 1 time.
timer.addEventListener(TimerEvent.COMPLETE, fadeBackOut);
timer.start();
}
function fadeBackOut(e:Event):void{
myTween = new Tween(text_mc, "alpha", Strong.easeIn, 1, 0, 2, true);
timer = null;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|