Jump to content
GreenSock

snowscarecrow

Animate to random label

Moderator Tag

Recommended Posts

Hi

 

Im trying to make an animation with random number to animate in different time in timlelinemac, so long everything is fine.

Then I have so sync several animations and make labels at different time stops.

 

The problem Im having after that is - I made random numbers between 1-11 and then I want to make a tween to a label with a number "1", "2" and so on.

 

var tlCC:TimelineMax = new TimelineMax({paused:true});
tlCC.addLabel("1",1.2);
tlCC.addLabel("2",2.14);
tlCC.addLabel("3",3.14);
tlCC.append(animateInReverse(mc_02));

btn.onRelease = function()
{

tlCC.timeScale = 10;
var kalle = random(11) + 1;
tlCC.tweenTo(kalle);
// How do I get the random number kalle between 1-11 to animate to the same variable 1 to 11.
// As it is now it's animating in time not to a variable with a timename.
// couldn't make a dynamic reference with [] either...
trace(kalle);

};

 

Or should I consider a different solution, like store all the variables in a array and random through all of them and tweenTo that array?

 

Probably easier to understand if you look at the attached file.

Really stuck here, and help would be great :-)

random_label_question.zip

Link to comment
Share on other sites

The problem is that TweenTo()'s parameter is a time OR label. If you pass in a Number it is treated as a time. If you pass in a String it is treated as a label.

 

tweenTo(1) // goes to a time of 1
tweenTo("1") // goes to the label named "1"

 

Try converting kalle to a String like so:

 

tlCC.tweenTo( String(kalle) );

Link to comment
Share on other sites

Hi Carl

 

That was exactly what I was looking for!

 

Thanks a bunch!

:-D :grin: :-D

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