Jump to content
Search Community

TimelineMax creates with random startTime

kittichai test
Moderator Tag

Recommended Posts

I have create a TimelineMax using command like this:

 

_timeline = new TimelineMax({paused:true});

 

I trace debug my code before and after this simple line of code and found out that startTime is not 0. It keeps increase value anytime I repeat this line of code to the point that any tween inside it won't run at all because startTime increase to like 7,000+ seconds

 

So, I try to add initial value like this:

_timeline = new TimelineMax({paused:true, startTime:0});

 

And trace, the startTime still increase.

So, I add your source code and trace into your class, and found the line of code that cause startTime to initialized at value not 0.

 

It's in TweenCore.as line 89

 

 

 

var tl:SimpleTimeline = (this.vars.timeline is SimpleTimeline) ? this.vars.timeline : (this.vars.useFrames) ? TweenLite.rootFramesTimeline : TweenLite.rootTimeline;

 

after execute the above line, tl seems to have rawTime, startTime, cachedTotalTime to be non-zero value. Note that the value is random and keep increasing everytime I run the code, so I don't post the value here.

 

What happen? I really can't understand that line of code much, but it seems that tl is assigned with static variable TweenLite.rootTimeline which still have some junk value in it. Can I reset those value?

Link to comment
Share on other sites

I trace the source code and found that TweenLite.rootTimeline has been assigned via TweenLite.initClass();

So, I add source code that call this class directly in my initialize module, but it makes my program not animate at all, just like your recommendation not to call it.

 

So, how can I reset TweenLite.rootTimeline?

Link to comment
Share on other sites

You should never reset TweenLite.rootTimeline. And the values you're tracing aren't "junk" or "random" at all. When the tweening engine initializes for the first time, it creates rootTimeline (and rootFramesTimeline) and records the time using getTimer(). Then on every frame, it updates its timing values based on Flash's getTimer(). Think of it as kinda like a root MovieClip timeline that starts playing and then whenever you create a tween, that tween gets put onto the rootTimeline at that specific time (whenver its' created plus any delay you define). So if it has been 10 seconds since the engine initialized, the rootTimeline's currentTime would be 10. And if you create a tween at that point, the tween's startTime would be 10. If your tween's duration is 5, for example, and you force the tween's startTime to be 0, it would immediately skip to its end values because at rootTimeline's 10-second spot, the tween would have already finished 5 seconds ago!

 

Help me understand why you're trying to change your tweens' startTime values.

Link to comment
Share on other sites

Originally, I don't want to do anything with startTime. But my animation run into strange problem, it can only run once and have to restart program to make it run again. My program is quite complicate to post here, but it works like this. It will load files from user's selection and animate. Since user can change files and play, every time they play it I have to recreate Timeline and Tween to make sure that it reflect newly update content. I trace my program and found out that the more time user press play, the higher the initial value of startTime property of Timeline. For example:

 

1st play - Timeline.startTime value as I planned, in animation, let's say 2 seconds.

2nd time - the same line of code creates Timeline.startTime increase to 10 seconds

3rd time - it create Timeline.startTime at 30 seconds..... and so on and on

So, it keeps getting higher and higher to the point where animation won't occur at all.

 

But, as you explain, startTime is global clock refer to the creation of Timeline engine (which I don't see it any where in documents), shouldn't you just make it read-only property?

 

Refer to your documents of TweenCore.startTime, it said "Start time in seconds (or frames for frames-based tweens/timelines), according to its position on its parent timeline"

 

Question 1: So, let me guess, if this Timeline has no parent, just like the Timeline I created, then its startTime is refer to global, right? and if it been insert into another Timeline, then it is change to refer to its parent?

Question 2: And, if so, can I change startTime only when it's inside another Timeline?

 

If so, then I will have to review my program again with this understanding.

Link to comment
Share on other sites

But, as you explain, startTime is global clock refer to the creation of Timeline engine (which I don't see it any where in documents), shouldn't you just make it read-only property?

 

I don't understand - why would I make it a read-only property? It can be quite useful if, for example, you place a tween on a timeline at 2-seconds and then later want to move it to start at 5-seconds (or whatever). Or do myTween.startTime += 10 to schedule it for 10 seconds later than what it currently is. What is the benefit of making it read-only?

 

Refer to your documents of TweenCore.startTime, it said "Start time in seconds (or frames for frames-based tweens/timelines), according to its position on its parent timeline"

 

Yep, that's exactly right. Is something unclear about that? Are you saying I should add text about the root timeline and how it is the default? And that it runs consistently, so its currentTime increases? I believe the root stuff is mentioned elsewhere in the docs already, but maybe you're saying I should add it here too?

 

Question 1: So, let me guess, if this Timeline has no parent, just like the Timeline I created, then its startTime is refer to global, right? and if it been insert into another Timeline, then it is change to refer to its parent?

 

Yep. By default, all tweens/timelines are on the root. If you nest a tween inside a timeline if your own, then its not on the root anymore and its startTime would be in relation to its new parent timeline's starting position. Just like nested MovieClips on the stage that have their registration point at different places. Their x/y properties are always in relation to their parent's local coordinate space.

 

Question 2: And, if so, can I change startTime only when it's inside another Timeline?

 

No, you can change startTime regardless of which timeline it's nested in - the root or your own custom one.

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...