Jump to content
Search Community

killTweensOf by "label"? [SOLVED]

viatropos test
Moderator Tag

Recommended Posts

Hey,

 

I would like to be able to kill the tweens of an object based on what the tween is doing, preferably by a "label" or something.

 

So if I have one object, as Square, and I'm tweening it using two separate TimelineLites, one tweening the position, the other tweening the scale (scale is tweened on rollover, position is tweened on click), such as:

 

var timeline:TimelineLite = new TimelineLite();
timeline.append(TweenLite.to(square, 1, {x:1000}));
timeline.append(TweenLite.to(square, 1, {y:1000}));

timeline= new TimelineLite();
timeline.append(TweenLite.to(square, 1, {scaleX:2, scaleY:2}));

 

...and I want to use TweenMax.killTweensOf(square) on every rollover/click, how do I make it so it only kills the click tweens on click, and rollover tweens on rollover? Is this built in, or do I have to manually manage it?

 

This is a basic example so there's probably other ways to do it, but I have some pretty complex tweens, and maybe 5 different timelines for an object, and I only want to kill one of the timelines on overwrite, how do I do that?

 

Basically, I would just like to prevent onComplete being called if the tween is interrupted...

 

Thanks!

Lance

Link to comment
Share on other sites

I can solve it by just killing the timeline, storing that in a Dictionary/Object. Not super clean, but it works :)

 

protected static var masterLabelList:Object = {};

protected function constructTimeline(options:Object):void
{
var label:String = (options && "label" in options) ? options.label : null;
remove(label);
timeline = new TimelineMax();
add(label);
}

protected function remove(label:String):void
{
if (!label || !timeline)
	return;

var timelines:Array = masterLabelList[label];
if (!timelines)
	return;
var children:Array;

var i:int = 0;
var n:int = timelines.length;
var j:int;
var q:int;
for (i; i < n; i++)
{
	children = timelines[i].getChildren();
	j = 0;
	q = children.length;
	for (j; j < q; j++)
	{
		children[j].kill();
	}
}
}

protected function add(label:String):void
{
if (!label || !timeline)
	return;

masterLabelList[label] ||= [];
masterLabelList[label].push(timeline);
}

 

Thanks,

Lance

Link to comment
Share on other sites

you can just kill() a TimelineLite/Max - you don't need to getChildren() and kill them all individually. If you've got one timeline for rotation and one for scale and you want to be able to kill them independently, you could just:

 

var scaleTL:TimelineLite;
var rotationTL:TimelineLite;

function myScaleFunction():void {
   if (scaleTL) {
       scaleTL.kill();
   }
   scaleTL = new TimelineLite(...); //build your scale timeline here
}

function myRotationFunction():void {
   if (rotationTL) {
       rotationTL.kill();
   }
   rotationTL= new TimelineLite(...); //build your rotation timeline here
}

 

You can also clear() a timeline if you want to keep the timeline itself but remove all the children (or an Array of specific ones). Lots of flexibility.

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.
×
×
  • Create New...