Jump to content
GreenSock

andyhullinger

Dynamic MovieClip references passed into TimeLineLite/Max?

Recommended Posts

Is it possible to pass-in a movieclip reference to a TimelineLite/Max instance? I want to reuse this timeline animation every time a "tooltip" movie clip is rolled over (via passing in the event.target). This "tortured" code almost works, but I can't seem to correctly clear() or "respawn" a fresh TimeLineLite instance each time.

 

 

 

var anime:TimelineMax = new TimelineMax();

someMC.addEventListener(MouseEvent.ROLL_OVER, myRollover);

function myRollover(e:MouseEvent):void {
sendClipToTimeLineLite(e.target);
anime.play();
}

function setClip(mc):void {
anime.appendMultiple([TweenMax.to(mc.child1, .2,{alpha:0}),
TweenMax.to(mc.child2, .5,{width:160}),
TweenMax.to(mc.child2, .5,{height:170}),
TweenMax.from(mc.child3,.2,{autoAlpha:0})], 0, TweenAlign.SEQUENCE);
}

Link to comment
Share on other sites

Is there a reason you keep appending stuff instead of creating a new timeline on each rollover? The way you're doing it has several problems with it, one of which is that you end up with a super long TimelineMax that has a bunch of stale tweens in it that you don't need anymore anyway. I also think you're misunderstanding how the timing works in a TimelineMax - please see the explanation in point #2 here: viewtopic.php?f=1&t=2324&p=8709#p8709

 

I'd probably do something like:

var anime:TimelineMax = new TimelineMax();

someMC.addEventListener(MouseEvent.ROLL_OVER, myRollover);

function myRollover(event:MouseEvent):void {
  var mc:MovieClip = event.target as MovieClip;
  anime = new TimelineMax();
  anime.append( TweenMax.to(mc.child1, .2,{alpha:0}) );
  anime.append( TweenMax.to(mc.child2, .5,{width:160}) );
  anime.append( TweenMax.to(mc.child2, .5,{height:170}) );
  anime.append( TweenMax.from(mc.child3, .2, {autoAlpha:0}) );
}

Link to comment
Share on other sites

  • 2 weeks later...

ahha! I was looking at the trees and missed the forest. Thanks!

Link to comment
Share on other sites

  • 3 weeks later...

I have been stumped hard on this one. I am calling my timeline in a rollover and calling my movieclip(with nested movieclips) dynamically. I'm trying to reference the nested movieclips. This might not even be related to TimelineLite but to some actionscript 3.0 I haven't yet learned. Here's the code

function over(evt:MouseEvent) {
evt.target.parent[mcname].mouseChildren=false;
var mcname=evt.target.name;
var timeline1:TimelineLite = new TimelineLite();
timeline1.appendMultiple([TweenMax.to(mcname.block1, .92, {bezier:[{x:0, y:0}]}),
						TweenMax.to(mcname.block2, .92, {bezier:[{x:0, y:0}]})]);

}

addEventListener(MouseEvent.MOUSE_OVER, over);

I've learned that to tween the movieclip that is rolled over I refer to it as "this[mcname]". I am unable to reference the movieclips within the outermost movieclip "mcname". Any help would be much appreciated!

Link to comment
Share on other sites

Yeah, you need to reference the actual object, not its name. For example:

 

BAD:

function over(evt:MouseEvent) {
   var mc = evt.target.name;
   var child = mc.block1; //in this case, mc is a String which can't have a "block1" property
}

 

GOOD:

function over(evt:MouseEvent) {
   var mc:MovieClip = evt.target as MovieClip;
   var child:DisplayObject = mc.block1;
}

 

And you're right - that's just an ActionScript thing and is unrelated to TweenLite/Max specifically.

 

Happy tweening

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×