Jump to content
Search Community

How to implement : timeline.add("my own function", n) in TimelineLite()

orta test
Moderator Tag

Recommended Posts

Hi guys, I have a questions about the using of TimelineLite(),

I hope to move two objects at the same time, and the rotation of one of both will be changed after a short delay, 

so my code is shown below:

 

 

private var timeline:TimelineLite = new TimelineLite();

 

timeline.add( new TweenLite(obj1, 1,  {x:0, y:15,z:15}),0);  // move obj1
timeline.add( new TweenLite(obj2, 1,  {x:0, y:-15,z:-15}),0);// move obj2
timeline.add(Obj_Rotater(obj1,0,0,20),3); // rotate obj1 along Z-axis after 3 second
 
private function Obj_Rotater(obj:ObjectContainer3D,rx:Number,ry:Number,rz:Number):void
{
obj.rotationX = rx;
obj.rotationY = ry;
obj.rotationZ = rz;
}

 

 

However, when the code is running, the Obj_Rotater function is executed immediately with the above two TweenLite function.

Is there any suggestion to help me ?

Thanks!!

Link to comment
Share on other sites

Yup, use call()

timeline.call(Obj_Rotater, [obj1, 0, 0, 20], 3)

http://greensock.com/asdocs/com/greensock/TimelineLite.html#call()

 

Hi Carl,

Thank you for your help, and the code is ok.

But I have another question about it:

How to implement one function from one class in timeline.call?

 

The one function of 'Water' class code is shown below:

 

public function animatorStart():void
{
addChild(particleMesh);
animator.start();
}

 

The 'Main' code is like:

 

private var Water1:LoadWater;

 

timeline.add( new TweenLite(obj1, 1,  {x:0, y:15,z:15}),0);  // move obj1
timeline.add( new TweenLite(obj2, 1,  {x:0, y:-15,z:-15}),0);// move obj2

timeline.call(Water1.animatorStart(),[], 2.5); // water effect is on after 2.5s

 

But the timeline.call can not work following the above code.

 

Also, I tried timeline.add function like: 

 

timeline.add( new TweenLite(Water1, 1, {onComplete:Water1.animatorStart()}), 2.5);

 

It did work but the delay can not be implemented.

 

Hope your response and thank you!!

Link to comment
Share on other sites

You need to remove the () from the function calls

 

bad - calls animatorStart() immediately

timeline.call(Water1.animatorStart(),[], 2.5); 

 

good - pases a reference to the animatorStart function

timeline.call(Water1.animatorStart,[], 2.5); 

 

same goes for using the onComplete of a tween

 

bad

timeline.add( new TweenLite(Water1, 1, {onComplete:Water1.animatorStart()}), 2.5);

 

good

timeline.add( new TweenLite(Water1, 1, {onComplete:Water1.animatorStart}), 2.5);

 

better (uses to() instead of add())

timeline.to(Water1, 1, {onComplete:Water1.animatorStart}, 2.5);

 

Does that work for you?

Link to comment
Share on other sites

You need to remove the () from the function calls

 

bad - calls animatorStart() immediately

timeline.call(Water1.animatorStart(),[], 2.5); 

 

good - pases a reference to the animatorStart function

timeline.call(Water1.animatorStart,[], 2.5); 

 

same goes for using the onComplete of a tween

 

bad

timeline.add( new TweenLite(Water1, 1, {onComplete:Water1.animatorStart()}), 2.5);

 

good

timeline.add( new TweenLite(Water1, 1, {onComplete:Water1.animatorStart}), 2.5);

 

better (uses to() instead of add())

timeline.to(Water1, 1, {onComplete:Water1.animatorStart}, 2.5);

 

Does that work for you?

 

Thanks Carl !!!

It works very well and my questions have been solved. That is amazing !! 

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