Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Greg Stager

Using Variables in an Object Name

Recommended Posts

I am having a little trouble working a variable into an object name.

For instance, suppose I have 30 boxes named box1alpha, box2alpha, box3alpha, etc.

I have tried to drop a variable in the middle of an object name and it seems to work the first time but when the variable is changed it doesn't.

 

In the codepen - I am expecting each box to move down with each click as the num variable is incremented.

How can I get the animation to read the new variable on subsequent plays?

 

See the Pen mdPrNrz?editors=1111 by Arelwynn (@Arelwynn) on CodePen

Link to comment
Share on other sites

You can't change the target of a tween like that.

 

It's best to create a new tween/timeline when you want to animate a a new target. :)

 

  • Like 2
Link to comment
Share on other sites

Bummer - this method would have worked much slicker than having 30+ tweens.

Link to comment
Share on other sites

You can just use a functions and loops to do the heavy lifting for you. You can even use a global vars object of values and pass it to the tweens if that works in your situation. If you want to share more, maybe we can point you in the right direction.

 

Happy tweening.

:)

 

  • Like 1
Link to comment
Share on other sites

Look at Blake getting all fancy today.

giphy.gif

  • Haha 1
Link to comment
Share on other sites

9 minutes ago, PointC said:

Look at Blake getting all fancy today.

 

It's get fancy with gsap week.

  • Like 2
  • Haha 2
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.

×