Jump to content
Search Community

choosing which properties to tween

blase test
Moderator Tag

Recommended Posts

why cant you write a tween with bunch of properties, (i just copied the first tween i had by my hand), but imagine there are more properties involved, and then you just call a function, pass parameters you want to tween and voila :D

 

function tween():void {

for (var i:int = 0; i < contentArr.length; i++) {

	TweenMax.to(contentArr[i], .5, {x: valueX , 
						y: valueY, 
						rotation: valueR, 
                                                       delay: _delay,
						ease: _ease });
}
}

Link to comment
Share on other sites

Could you restate your question? I don't understand what your objective is exactly. You can pass whatever properties in that you want. And if you prefer to create a wrapper function that allows you to pass in variables and it dynamically builds the tween, go for it. If you want to tween multiple targets to the same values, use v11's TweenMax.allTo() method. http://blog.greensock.com/v11beta/

Link to comment
Share on other sites

And if you prefer to create a wrapper function that allows you to pass in variables and it dynamically builds the tween, go for it.

 

how would this look like?

 

something like this?

 

var circles:Dictionary = new Dictionary();

circles[circle1] = new Object();
circles[circle1].scaleTween = {scaleX:5, scaleY:5, transition:"easeOutElastic"};
circles[circle1].locationTween = {x:middleX, y:middleY, transition:"easeInOutBounce"};
circle1.addEventListener(MouseEvent.CLICK, clicked);

function clicked(e:MouseEvent):void {
  var tweenProperties:Object = circles[e.currentTarget];
  TweenLite.to(e.currentTarget, 0.5, tweenProperties.scaleTween);
  TweenLite.to(e.currentTarget, 0.5, tweenProperties.locationTween);
}

Link to comment
Share on other sites

Sure, but two cautions:

 

1) You're using transition:"easeOutElastic" but that looks like Tweener syntax. With TweenLite, it's ease:Elastic.easeOut (don't forget to import the easing equation)

 

2) You're creating two tweens of the same object, but the second one will overwrite the first one unless you set overwrite:false or initialize OverwriteManager once, like OverwriteManager.init(2). See http://blog.greensock.com/overwritemanager/

Link to comment
Share on other sites

lets say i wanted to do this:

 

public static function array( arr:Array, _time:Number, _properties:Object ):void {

		for (var i:int = 0; i < arr.length; i++) {

			TweenLite.to( arr[i], _time, _properties );

		}
	}

 

 

is there a way to tween an array but with some specifics?

for example:

 

var prop:Object  = { x: Math.random() * stage.stageWidth , y: Math.random() * stage.stageHeight, delay: i * tweenTime };
Tween.array( arr, tweenTime, prop );

 

this will tween all objects in array to the same point, but i would like to apply Math.random() to every one independently.

also, how could i implement a delay this way, cause i dont have access to i.

 

and here for example, i would also need an access to i variable in the for loop.

 

var prop:Object = { x: pointArr[i].x, y: pointArr[i].y };
Tween.array( arr, tweenTime, prop );

 

is there a way to somehow implement that?

 

Thanks!

Link to comment
Share on other sites

Why not just do the tweens in a loop?

 

for (var i:int = 0; i     TweenLite.to(arr[i], time, {x:pointArr[i].x, y:pointArr[i].y, delay:i * time});
}

 

Also, note that in v11, TweenMax.allTo() has a "stagger" parameter that allows you to stagger the start times. It won't help if you want all the destination values to be different, but I figured I'd mention it nonetheless. http://blog.greensock.com/v11beta/

Link to comment
Share on other sites

Reusable in what way? I don't see the problem. Do you want to do something like:

 

function doSomething(index:uint):void {
   TweenLite.to(arr[index], time, {x:pointArr[index].x, y:pointArr[index].y, delay:index * time});
}
doSomething(4); //does something for the object at index number 4 in the arr array

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