cerulean Posted May 14, 2013 Posted May 14, 2013 As I understand it, a Timeline is set up so that it uses the values of variables at the time the timeline is created. Thus, if n=100 tl.to(mc,1,{x:n}); will move mc to x = 100. What happens if I do var n:int = 100; tl.addCallback(function() {n = 200}); tl.to(mc,1,{x:n}); More importantly, what if I want the timeline to use values that are determined at the time the timeline plays? (Yes, I could do a test of above, but I'm trying to understand this once and for all, conceptually — I'm setting up complex timelines with many moving parts and subcalls, and trying to understand what is called/evaluated now and what is called/evaluated later). Thanks for any insight(s)!
Carl Posted May 15, 2013 Posted May 15, 2013 Yes you are correct in that the ending values that you specify in tweens are recorded when the tween is created, and in this case, added to a timeline. The starting values of a tween get evaluated and recorded the first time the tween runs. As for creating a timeline and then at runtime altering the end values of tweens while the timeline is running, its not a trivial task. Although this discussion focuses on JavaScript the exact same concepts apply to AS3. That thread has few solutions but there are 2 that I like. if a tween needs to change at runtime: remove it from the timeline and put a new one in its place or use a TweenMax tween for which you store a reference and use TweenMax.updateTo to change the end values. both concepts are discussed in the linked thread above. 1
jamiejefferson Posted May 15, 2013 Posted May 15, 2013 Also, don't forget that in AS3, primitive types aren't really passed by reference (well, they are, but behave like they are passed by value).In this: var n:int = 100; tl.to(mc,1,{x:n}); the vars object passed to tl behaves no differently to {x:100}, because n is a primitive type int. GSAP has no way of knowing that n was ever involved. 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now