Jump to content
Search Community

[TimelineMax + TweenMax.to] real time destination calculatio

Miroku_87 test
Moderator Tag

Recommended Posts

Hi everyone,

I'm using TimelineMax with a few tweens. These tweens have to move above another object, so to its exact coordinates.

The problem is this: this object is tweened itself at the same time for other reasons, so I can't retrive its coordinates at the time I create the timeline, because after the timeline play command that object could be moved somewhere else.

 

Example of what I CAN'T do:

function somewhere():void
{
   timeline = new TimelineMax();
}

function example():void
{
   var newX = overObject.x;
   var newY = overObject.y;

   timeline.append(TweenMax.to(obj, 5, {x: newX, y: newY}));
}

function somewhereElse():void
{
   timeline.play();
}

 

Is there a way to avoid this problem and get my coordinates at the time the timeline plays that single tween?

 

I've tried this way:

function example():void
{
   var newX = overObject.x;
   var newY = overObject.y;

   timeline.append(TweenMax.from(obj, 5, {onInit: calculateCoords, onInitParams: obj, x: obj.x, y: obj.y}));
}

function calculateCoords(ofWhat:Object):void
{
   obj.x = overObject.x;
   obj.y = overObject.y;
}

but something is not right in this and infact it does not do what expected.

 

So how?

Thank you in advance =)

Link to comment
Share on other sites

did

 

timeline.append(TweenMax.from(obj, 5, {onInit: calculateCoords, onInitParams: obj, x: obj.x, y: obj.y}));

 

pass the parameters into your calcualateCoords function?

 

i thought it the params had to have array synax like so:

 

timeline.append(TweenMax.from(obj, 5, {onInit: calculateCoords, onInitParams:[ obj, x: obj.x, y: obj.y]}));

Link to comment
Share on other sites

Oh, you're right, I forgot to put them like this:

function example():void
{
   var newX = overObject.x;
   var newY = overObject.y;

   timeline.append(TweenMax.from(obj, 5, {onInit: calculateCoords, onInitParams: [obj], x: obj.x, y: obj.y}));
}

function calculateCoords(ofWhat:Object):void
{
   obj.x = overObject.x;
   obj.y = overObject.y;
}

 

but in my code they are present.

Link to comment
Share on other sites

Maybe if I could do something like:

 

function example():void
{
   var newX = overObject.x;
   var newY = overObject.y;

   timeline.append(TweenMax.to(obj, 5, {onInit: updateCoords, onInitParams: [thisTween], x: newX, y: newY}));
}

function updateCoords(ofWhat:TweenMax):void
{
   var newX = overObject.x;
   var newY = overObject.y;
   ofWhat.vars =  {x: newX, y: newY};
}

would it change something?

 

is there a way to refer to the tween we're creating like I did in the "onInitParams" ?

 

EDIT: I did a little test and it seems to work.. still I need how to self reference the tween =\

OR I could do something else like this:

 

function example():void
{
   var newX = overObject.x;
   var newY = overObject.y;

   timeline.append(TweenMax.to(obj, 5, {onInit: updateCoords, onInitParams: [obj], x: newX, y: newY}));
}

function updateCoords(ofWhat:Object):void
{
   var newX = overObject.x;
   var newY = overObject.y;
   var tweens:Array = TweenMax.getTweensOf(ofWhat); 
   tweens[0].vars =  {x: newX, y: newY};
}

 

This works good, but what if I'm using allTo? What do I write in my "onInitParams"? How do I refer to the single tweened object of the array?

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