Jump to content
Search Community

Loop DisplayObject

youwh test
Moderator Tag

Recommended Posts

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

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

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

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

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

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