Jump to content
Search Community

Add TweenMax as variable to a Timeline

MarioLapone test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a "simple" question (I think that it doesn't need a codePen sample).

We have a variable like this:

var tx = "TweenMax.to('#element',2,{textShadow:'10px 10px 10px rgba(255, 255, 255, 0.5)'})";

I take it from an xml file.

Can I do something like this?

tml.add(tx, s);

Where "tml" is a timeline and "s" the time in seconds. With this sintax it doesn't work (no error and nothing happens). Is there some other way to do this?

Thank you very much for your patience.

Mario

Link to comment
Share on other sites

Hey @MarioLapone,

 

Do you see why your code doe not work?

 

What you are doing is trying to add a string into your tml. You can only add a Tween, Timeline or a function into another timeline.

 

GSAP is smart but not omniscient. It doesn't know that string you have passed is meant to be a Tween. That it should parse the string and convert into a Tween/Timeline object...

  • Like 1
Link to comment
Share on other sites

Yes, it is just that. I hoped that GSAP was omniscient.


Seriously, I asked this because I have a xml file with structured istructions used by a javascript function that builds a timeline. All works very well.
BUT sometimes the tweens could be very complicated and unpredictable and the istructions are not so "structured" and i tried the solution that i asked. It's evident that it was a stupid solution.

 

Thank you for your answers.


Regards.
Mario
 

Link to comment
Share on other sites

I wouldn't call it stupid. More like wishful. It would be great to have that.

 

But, having said that, you could, in theory build your own Tween factory that reads such string and spits out an actual GSAP object.

 

So, really, it is possible, it's just not in the library. You could create your own plugin.

  • Like 1
Link to comment
Share on other sites

eval is certainly controversial. Many people say to avoid it like the plague.

 

Others assert that it's not really a significant risk when running locally in a browser and accepting local arguments.

 

I'm not advocating it, I don't know enough about it. I'm just wondering if it really presents a significant security risk in this context. 

 

 

Link to comment
Share on other sites

On 2/2/2018 at 7:15 PM, Visual-Q said:

I'm not advocating it, I don't know enough about it. I'm just wondering if it really presents a significant security risk in this context. 

 

It all comes down to whether or not you can trust that the string is what you think it is. If it comes from your sever, and has been validated, then the risk is low. If it's based on some user input, like a form, input, or url, then the risk is high.

 

See how exploits work here.

https://en.wikipedia.org/wiki/Cross-site_scripting#Exploit_examples

 

 

 

@MarioLapone

 

If you need help creating the data/instructions for your animations, this thread might be useful.

 

 

 

See the Pen 7d3275656ef955c5ea2eb121c2407ba6 by osublake (@osublake) on CodePen

 

 

 

 

 

 

 

 

  • Like 5
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...