Jump to content


regarding multiple tweens & kill()

Recommended Posts

Hi Jack.

Heres my situation. sorry for the story, but I thought it would explain better vs some code.


I have two main displays to show : an overview and some detail views.

Attached to a lineholder i add my pathfollowers.

Then i tween the followers

all this happens in a loop. now this loop its length is quite variable. my biggest loop so far goes over 2000.

something like this:

myPath .addFollower(createCircle(5, 0x006699), (i/ connectionArray[i].@myvar), true);
overviewTween = TweenMax.to(myPath , (connectionArray[i].@myvar), {progress:1,repeat:-1, ease:Linear.easeNone});
lineHolder.addChild(myPath );


//createCircle is a simple function to draw a dynamic dot of 5px with a color these are added to its own child layer named (dotHolder)


All this runs okay. and with my skills I didn't find a way to code this any more optimal but heres the catch.

When I click an item that needs a detail view(showing even more tweens. the (new) tweens become very slow.


I remove my children with this function

function removeChildren():void
while (lineHolder.numChildren)
while (dotHolder.numChildren)
       if (dotHolder.numChildren == 0)
//does nothing, but without it get errors, as some items has no children	
trace ("remove lines and dots");



so here is question nr 1: Does the tweens stop(calculating, free up memory) automatically when I remove the children?

question 2: could it be that the cpu is massive due to the way i keep my tweens continuously?

In otherwords. the dots flow from point A to B and then restart from its original position, never ending.


consider this situation: the user clicks back and forth between overview & detail, on and on, I am concerned that this all will slow down the application.


I've currently experimented with the following code in the removeChildren function

var currentconnections = connectionArray.length();
while (currentconnections--)


Which seems to work okay, but all this story telling above, has one major question. Is this a good way to tackle my situation in a -nearly- optimal cpu friendly way?

again; please take in regards that the data to be shown (aka for loop(+- 2000 times) with the PathFollower tween) will recreate itself every 10 seconds.

+ there are about 8 more user-functions that can happen while all this is happening(ofcourse in all situations the tweens will be killed (if needed)).


I hope my questions are somewhat clear. I've been working on this for a week now. and duno anymore whats good / bad practice.

motivating it sure is. If you want I can screen share the project to you Jack through skype, just let me know and i'll pass on my handler.

I sure respect privacy and all that. but I can't put this project(or code) in the open at this point.


Thank you for your time, and sorry for the lengthy post.

Link to comment
Share on other sites

When you removeChild() your objects from the display list, it makes absolutely no difference to TweenLite/Max. So yes, you should definitely kill() the tweens especially if they're repeating infinitely. Your killTweensOf() idea is fine - that should work although without seeing the rest of your code in context, I can't say for sure if you're optimizing everything well.


One optimization that you might be able to implement is tweening the path's progress property instead of tweening each individual PathFollower's progress property (I assume you wanted them all to move together anyway). That could significantly reduce the number of tweens you have happening at once.


As far as other things bogging down, it's pretty tough to diagnose based on what you posted here. If you still need help, feel free to create a separate, simplified FLA that demonstrates the issue (please don't post your production files with non-critical code).


Hope that helps!

Link to comment
Share on other sites

Thanks again Jack for the insight, glad I was on the right track.


however -after reading the docs-

I am not very sure how to tween the path's progress.


But after killing the tweens & some additional optimalisation so far the project runs at a steady 25-30 fps.

with over 6000 loops going on. Which is lovely to see.

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.