Skip to main content
Known Participant
September 4, 2009
Question

addChild with tweened fadeIn?

  • September 4, 2009
  • 2 replies
  • 1626 views

Hello all,

I am just trying to get my as3 tweening skills locked down around the basics. So, for this example, I have a logo / home button fading in, this code is working for that... however, is there a way to addChild (home in this case) via the tween code, so that I do not have to add the child at alpha0 "then" fade it in?

import fl.transitions.Tween;
import fl.transitions.easing.*;

var home:Logo = new Logo();
addChild (home);
home.x = 400;
home.y = 300;
home.alpha = 0;


var fadeIn:Tween = new Tween(home,"alpha",None.easeNone,0,100,200,true);

This topic has been closed for replies.

2 replies

Inspiring
September 4, 2009

BTW, I would recommend that you also use the visible property. If you set something's alpha to zero and then addChild() to the display list, it is on the stage and active -- even if it can't be seen. This means that if you are giving it mouse event handlers or the like it will be active and able to respond. If you set it's visible property to false it won't respond to those events.

I'm ashamed to say that I haven't used TweenLite or TweenMax, but I have been meaning to do so. I do think there is some kind of switch in it that you can tell it to make visible false when alpha hits zero -- or not as the case may warrant.

bamaurerAuthor
Known Participant
September 5, 2009

Oh, that makes sense ­ thanks for the tip.

September 4, 2009

To answer your question, no - you will need to first set the alpha to 0 before tweening it up. Aside from that I highly recommend you start using TweenLite / TweenMax instead of the built in tweening classes. The built-in ones are really slow, problematic and downright ugly to read.

Same tween in TweenLite - almost I do not see where you specify the time for the tween?

import gs.TweenLite;
import gs.easing.*;

home.alpha = 0;

TweenLite.to(home, 1, {alpha:1, ease:Linear.easeNone}); //one second fade up with no easing

Actually, I just realized you can do what you want with TweenLite's from method like so:

addChild(home);

home.x = 400;

home.y = 300;

TweenLite.from(home, 1, {alpha:0, ease:Linear.easeNone});

That will tween from alpha 0 to the current alpha, which is 1.

bamaurerAuthor
Known Participant
September 4, 2009

thanks dmen,

so i can just call tweenLite / TweenMax? or do i need to download and install those?

Ned Murphy
Legend
September 4, 2009

You'll need to download and install those classes.  I don't have a url, but a quick Google search for "TweenMax download" should reveal some.