Jump to content
Search Community

Positioning a tween with a variable

Guilherme test
Moderator Tag

Recommended Posts

Hello.

This is my first post. And I believe this is a noob question, in fact.

 

I have a tween that has a bezier effect on it and I want it to receive the "y" position through a variable.

Something like this:

 

var myTween: TweenLite = new TweenLite(my_mc, 2, {y: myVar + 43 , ease:Bounce.easeOut, onComplete: myFunction});

 

Is there a simple way to pass this value?

 

 

Thx in advance.

Link to comment
Share on other sites

I've got a few questions for you:

  1. Where are you trying to pass the value? Keep in mind that you can reference my_mc.y anytime (no need to do something special to pass that). Or maybe you're trying to reference a particular variable in your onComplete? Sorry, I'm a bit confused about what you're attempting here, so if you could provide some clarity that'd be great.
  2. You mentioned a bezier effect - where is that? I didn't see any "bezier" in your tween.

Link to comment
Share on other sites

Hello..

 

I'm sorry I should have written all the code. I thought it that would be enough.

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import fl.transitions.Tween;


var pontoFinal: Point = new Point (0,0);


var chegadaTween: TweenLite = newTweenLite(chegada_mc, 2, {y: pontoFinal.y + 43, ease:Bounce.easeOut, onComplete: DelayfadeChegada});

chegadaTween.pause();


function DelayfadeChegada(){
TweenLite.delayedCall(2, fadeChegada);
}
function fadeChegada(){
 TweenLite.to(chegada_mc, 5, { autoAlpha:0, onComplete: chegadaReverse});
}

function chegadaReverse(){

chegadaTween.reverse();
}


function detPontoFinal(){
pontoFinal.y = pontoFinal.y - 43;
pontoFinal.x = pontoFinal.x - 2;
return pontoFinal;
}


detPontoFinal();

chegadaTween.currentTime = 0;
TweenLite.to(chegada_mc, 0, { autoAlpha:1});

///////////////////////////////////////*

I have tried chegada_mc.y but for some reason my swf doesn't load.
So as TweenLite.to(chegada_mc, 0, {y:pontoFinal.y, x:pontoFinal.x});

*///////////////////////////////////////

TweenLite.to(chegada_mc, 0, {y:pontoFinal.y});
TweenLite.to(chegada_mc, 0, {x:pontoFinal.x});
chegadaTween.play();

 

 

Keep in mind that pontoFinal is defined in another section of the code.

Sorry, I have forgot that I changed the code and there is no more bezier in the tween.

 

Hope is clear now.

Link to comment
Share on other sites

Thanks for posting the code - unfortunately I still don't understand what your question is. What exactly is the problem? What variable are you trying to "pass" (from where and to where)?

 

You mentioned that referencing chegada_mc.y caused your swf not to load - is that correct? Sorry, I'm really confused here. I want to help, I'm just not sure what the problem or question is.

Link to comment
Share on other sites

There are a few things that could be going on here.

 

First, I don't know if this is your real code or something that you edited when posting but the following line is going to give you problems

 

BAD: newTweenLite

var chegadaTween: TweenLite = newTweenLite(chegada_mc, 2, {y: pontoFinal.y + 43, ease:Bounce.easeOut, onComplete: DelayfadeChegada});

 

GOOD: new TweenLite (space between new and TweenLite)

var chegadaTween: TweenLite = new TweenLite(chegada_mc, 2, {y: pontoFinal.y + 43, ease:Bounce.easeOut, onComplete: DelayfadeChegada});

 

I'm also a bit confused by why you are setting up chegadaTween using the pontoFinal values,

then calling the function that changes the pontoFinal values and then configuring 2 0-duration tweens on chegada_mc that use the new pontoFinal values.

 

Keep in mind, there is a very good chance I am just misunderstanding something.

 

In these situations sometimes it is is best to just focus on the core issue and step away from the more complex implementation.

 

Your initial post mentioned that you want to receive the values for your tween through a variable.

And yes, you most certainly can. The following will work fine:

 

 

var pontoFinal:Point = new Point(100,100);
TweenLite.to(chegada_mc, 1, {x:pontoFinal.x});

 

I think if you add some traces each time the pontoFinal values are being changed and referenced you will be able to track down why things aren't functioning exactly as you hoped.

 

If you need more assistance, it might be easier to help with a more basic example.

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