youwh Posted October 5, 2010 Share Posted October 5, 2010 I have multiple object doing random movement with random speed. i wanted to repeat the animation. I tried to use onComplete to restart each object once the animation end, but how could I specifically target it to that object? private function lineAnimation (e:DisplayObject):void { TweenLite.to (e,randomTime, {x:randomX, onComplete: lineAnimation(e)}); } Link to comment Share on other sites More sharing options...
GreenSock Posted October 5, 2010 Share Posted October 5, 2010 You're using the wrong syntax, that's all. Whenever you put "()" at the end of a function reference, it tells Flash to call that function and substitute the result wherever that function is. You should use onCompleteParams to pass parameters, like this: private function lineAnimation (e:DisplayObject):void { TweenLite.to (e,randomTime, {x:randomX, onComplete:lineAnimation, onCompleteParams:[e]}); } Link to comment Share on other sites More sharing options...
youwh Posted October 6, 2010 Author Share Posted October 6, 2010 It works! Thanx! Can we interrupt an ongoing animation? For example, base on the previous question, the animation is moving very slow like 10 seconds. Then in between that 10 seconds, some conditions have changed, and I want the function to re-start, base on a new speed given. if(slow){ TweenLite.to (e,randomTimeA, {x:randomXA ,onComplete:lineAnimation, onCompleteParams:[e]}); } else if (fast){ TweenLite.to (e,randomTimeB, {x:randomXA ,onComplete:lineAnimation, onCompleteParams:[e]}); } Link to comment Share on other sites More sharing options...
GreenSock Posted October 6, 2010 Share Posted October 6, 2010 Sure, you can do that. By default, TweenLite automatically handles overwriting previous tweens of the same object. Does that answer your question? If not, could you please restate it? Link to comment Share on other sites More sharing options...
youwh Posted October 6, 2010 Author Share Posted October 6, 2010 I have multiples object animation running on random speed (end time) , and it will restart when its animations end TweenLite.to (e,randomTimeB, {x:randomXA ,onComplete:lineAnimation, onCompleteParams:[e]}); While the animation is playing, I have a timer to check the correct speed it should be private function timesUp (e:TimerEvent):void { checkXML (); checkCondition (); (define correct speed) } How can I restart all the animation, since the 'e' is multiple object with random speed and ends/restart on different time? Link to comment Share on other sites More sharing options...
GreenSock Posted October 6, 2010 Share Posted October 6, 2010 Do you want to restart them all and send them to new random values? If so, just store your targets in an array and then loop through the array, creating new tweens whenever you want. If you need to keep the tweens going to wherever there end values are but you want to simply affect all of their speeds, you could insert them into a TimelineLite and then just affect the TimelineLite's timeScale to make everything speed up or slow down. See the video at http://www.greensock.com/timeline-basics/ for the basics. Link to comment Share on other sites More sharing options...
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