Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Changing a Tween's Duration? [SOLVED]

Recommended Posts

I am sure I must be missing something, but I'm stumped.


I have a TimelineMax instance, composed of Timelines and Tweens. One of the Tweens in this Timeline pads the end of the Timeline with 'dead time', which is implemented by this initialization code:


//laserSequence is a TimelineMax instance which has already had multiple inserts of various sorts		
//scale is the full time we want the whole animation to play
//laserSequence.duration is the amount of time occupied by 'meaningful' animation (stuff is happening on the screen)  
var deadTime:Number = scale - laserSequence.duration;
var waiting:TweenMax = TweenMax.to(null, deadTime, {});


I'm forming a 'bigger' animation by putting each individual laserSequence in another TimelineMax, but I don't believe that to be relevant for this problem.


This code works to create the initial Timeline correctly, that is, deadTime is appended to the laserSequence's animation length. However, if I attempt to update the duration of this 'null tween', caused by a scrubber on the front end that lets the user change the duration of an animation sequence, the laserSequence.duration value changes, but it still plays the original duration.


In my situation, deadTime is initially set to 15 seconds, and when I move the scrubber to the other end (which should change deadTime to 30 seconds), a display counter on the screen shows the animation counting down from 30 to 15, at which point it moves on to the next sequence. I would expect it would continue to play for another 15 seconds.


This is the code I'm using to attempt the duration change (I have tried several different alternatives, such as TimelineMax.remove(tween), TimelineMax.append(tween), but the same behavior occurs):

//each of these top level timelines is appended with a 'deadtime' tween
//get it, and replace it with one to match the new scale
var nullTween:TweenMax = timeline.getChildren(false, true, false).pop();

//this calculation determines the new required length of dead time						
var deadTime:Number = toolbarInstance.animationScale - (timeline.duration - nullTween.duration);

//update the tween that pads the end of the animation
nullTween.duration = deadTime;


The impression I get is that there's some kind of caching or something that needs to be refreshed, and while changing the duration value actually changes the value, it doesn't seem to be considering that when playing the animation.

Link to comment
Share on other sites

I got the latest update, but the behavior is the same.

Link to comment
Share on other sites

I just double-checked and it seems to work fine for me (changing the duration of the last tween in a timeline does indeed affect the tween properly and the timeline as well). Could you post an example FLA that demonstrates the issue?

Link to comment
Share on other sites

I made a simple example of the problem I have, based on the original code I had problems with, but I stripped out everything but the essentials.


There's a little code in the slider movieclip that's on stage, this is just to update the main code with the position of the slider. The main code is on the main timeline.


To test out the problem:

1. Publish the FLA. Immediately, the timeline will begin, and the seconds display will count down, starting at 15.

2. Before the counter goes down to 0, move the slider all the way to the right. This should lengthen each step to a duration of 30 seconds, starting with the next step.

3. Observe that once the timeline moves on to the second step (you'll see "done: variable - 1" in the trace), the counter begins at 30.

4. Notice that when the counter hits 15 (has been playing for 15 seconds), it resets back to 30 as it plays the third step. The expected behavior would be for it to count down all the way to 0 before playing the third step.

Link to comment
Share on other sites

Aha, I think I see the misunderstanding. When you change the duration of a tween inside a timeline, did you expect that all the other timelines would move their start times to adjust for the different duration? If so, that's not how it works. The child's startTime is determined when you insert/append/prepend it onto the timeline. Once they're inserted, positions are not relative - they're absolute. You can, of course, change a timeline's startTime if you want to, but altering a previous timeline's duration doesn't force all the ones after it to move back in time. Feel free to use the shiftChildren() method to move all the children by a certain amount (or just the ones after a certain time).


So just to be clear, if you've got three 15-second timelines sequenced on a parent timeline, and then you add 5 seconds to the duration of a tween in the first one (making the timeline 20 seconds long), the first and second timeline would overlap by 5 seconds. So once you hit 15 seconds, they'd both be playing for 5 seconds, and then just the 2nd one would for the remaining 10 seconds, etc. Make sense?

Link to comment
Share on other sites

Ah, it becomes clear. I had suspicions that something like that was happening as I built the sample FLA to illustrate.


Indeed, I was thinking that by changing the duration, the timeline would implicitly compensate by moving the 'later' timelines and their children back appropriately. This probably would have been easier to pick up on had I not been manipulating the duration of a tween that didn't really do any visual work. It would be extremely useful for my particular application, but probably not the desired behavior in general.


Anyway, I believe you've solved my misunderstanding, and I think I can make a fix. Thanks very much for the help!

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.