Jump to content
Search Community

Dynamic parameters and properties

gigbig test
Moderator Tag

Recommended Posts

Hi guys! My first topic here!

I have an array of pages, and I want to go to the previous/next one using tweens, with different types of transitions, horizontal sliding (x coordinate), vertical sliding (y coordinate), fading (alpha parameter) or rotation (rotationY parameter).

 

I want to convert classic tweens to tweenlite. The original code (for just one of the two pages moving) was


new Tween(pages[whatever], transitionType, Regular.easeOut, BStart, BEnd, transitionSpeed, true);

 

where transitionType can be "x", "y", "alpha" or "rotationY", corresponding to 4 MovieClip native properties.

 

The stupid way would be the following code:


switch (transitionType)
{

case "x" :
pages[whatever].x = BStart;
TweenLite.to(pages[whatever], transitionSpeed, {x : BEnd});
break;

case "y" :
pages[whatever].y = BStart;
TweenLite.to(pages[whatever], transitionSpeed, {y : BEnd});
break;

case "alpha" :
pages[whatever].alpha = BStart;
TweenLite.to(pages[whatever], transitionSpeed, {alpha : BEnd});
break;

case "rotationY" :
pages[whatever].rotationY = BStart;
TweenLite.to(pages[whatever], transitionSpeed, {rotationY : BEnd});
break;

}

 

I need a smarter coding like

 


pages[whatever].###transitionType### = BStart;
TweenLite.to(pages[whatever], transitionSpeed, {###transitionType### : BEnd});

 

in order to add n transitions corresponding to n MovieClip native properties without creating a giant switch, but just keeping 2 lines of code (classic tweens need just 1!).

 

The problem is that I don't know how to use a string as a tween parameter name or a Movieclip property name.

Can you help me, please?

Link to comment
Share on other sites

Using the "normal" TweenLite vars object I'm not so sure that is possible.

 

The good news is that TweenLiteVars makes this really easy: http://www.greensock.com/tweenvars/

 


import com.greensock.*; 
import com.greensock.data.TweenLiteVars;

var dynamicProp:String = "x";
var dynamicPropValue:Number = 300;

TweenLite.to(mc, 1, new TweenLiteVars().prop(dynamicProp, dynamicPropValue));

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