Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
MarioLapone

Add TweenMax as variable to a Timeline

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

Thank you.

It's a good idea.

Thank you again. I learned something.

 

Link to comment
Share on other sites

Ooooo.... Eval is dangerous...

 

Be very, very careful with it.

 

(But is a super simple way to achieve the required results)... Nice idea.

  • Like 1
Link to comment
Share on other sites

I know there are potential security concerns, presumably because it could be an access point for undesired code to be injected. I can't answer to the advisability of using it. Maybe the big guns here could weigh in on that.

Link to comment
Share on other sites

Yeah, I'd stay far, far away from eval(). It's a security concern, a performance concern, and I've heard of vendors flat-out blacklisting pages/scripts that use it anywhere. It's much better to structure your data in a way that'd allow you to re-form it properly in the JS context. 

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

Thank you, OSUblake. When i'll be back in office i'll be glad to study your interesting suggestions.

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