Jump to content
Search Community

Group of Tweens on Timeline

magic_77 test
Moderator Tag

Recommended Posts

Hi,

i´m stucking at the following:

i want to animate alway 2 mc as group

mc[0].y = 6 to -208

mc[1].y = 110 to -104

where mc[0] and mc[1] are already on the stage

then

mc[2].y to y = 6

mc[3].y to y = 110

then

mc[2].y to y = -208

mc[3].y to y = -104

then

mc[4].y to y = 6

mc[5].y to y = 110

 

so it should rotate continuously.

 


mainTimer.addEventListener(TimerEvent.TIMER, initAnim);
mainTimer.start();

private function initAnim(a:int=0):void {
 trace("a" + a)
 mainTimer.delay = 6000;
 myTimeline = new TimelineMax({
		tweens:[new TweenMax(sh[a], 1.5, {y:-208}),
		             new TweenMax(sh[a+1], 1.5, {y:-104}),
			     new TweenMax(sh[a+2], 1.5, {y:6}),
		              new TweenMax(sh[a+3], 1.5, {y:110})], align:TweenAlign.START, onComplete:myFunction});
	}
	private function myFunction():void {

		neu = (j+2) % Math.floor(json.order_feedback.items.length / 2);
		initAnim(neu);
		j = neu;			

	}

 

mybe someone can help me out?

thx in advance

Link to comment
Share on other sites

sorry but I really can't visualize what your code is doing.

the only thing I can suggest is maybe using tweenMax.fromTo() which allows you to set a start and end position of each tween.

 

based on your description I think you could pass each pair of objects into a function that returns a TimelineLite for that pair. Then append each group's timeline into a master timeline and set the timeline to repeat.

Link to comment
Share on other sites

Hi Carl,

thanks for your reply. Here you can see what i mean: http://hd-mailserver.de/main.html

my problem is that i can´t figure out how to manage this in a better way. I wanna build in two button to play

this forward and reverse.

i modified my code a little, but i doesn´t work for me the way i want.

...
private function setObjects() {

  ....code for setting objects on stage

 //startting anim
 mainTimer.addEventListener(TimerEvent.TIMER, initAnim);
 mainTimer.start();		
}
private function initAnim(e:TimerEvent) {
		mainTimer.delay = 6000;
		outAnim(j);
		neu = (j+2) % Math.floor(json.order_feedback.items.length / 2);
		inAnim(neu);
		j = neu;
	}
	function outAnim(a) {
	   myTimeline0 = new TimelineMax({
		      tweens:[new TweenMax(sh[a], 1.5, {y:-208}),
		              new TweenMax(sh[a+1], 1.5, {y:-104})], align:TweenAlign.START, onComplete:myFunction});
	}
	function inAnim(a) {
	   myTimeline1 = new TimelineMax({
		      tweens:[new TweenMax(sh[a], 1.5, {y:5}),
		              new TweenMax(sh[a+1], 1.5, {y:109})], align:TweenAlign.START, onComplete:myFunction});
	}
	private function myFunction():void {		}

 

maybe this example is some more clear - and mybe you have an idea

many thanks in advance

Link to comment
Share on other sites

thank you for posting the example swf. it made it very clear what you want to do.

 

take a look at what I came up with:

http://www.snorkl.tv/dev/upAndUp/

 

here is the code:

 

import com.greensock.*;

var numBars:int = 6;

var initY:int = 250;
var initX:int = 10;

var even:Object = {onScreen:6, offScreen:-208};
var odd:Object = {onScreen:110, offScreen:-204};

var bars:Array = [];

var currentSection:int = 0;

//0, 2, 4

var speed:Number = .5;


function createBars() {
for (var i:int = 0; i 		trace("make a bar");
	var bar:Bar = new Bar();
	bar.y = initY;
	bar.x = initX;
	bar.label_txt.text = String(i);
	addChild(bar);

	bars.push(bar);




}

//start the first 2 bars where they should be

bars[0].y = even.onScreen;
bars[1].y = odd.onScreen;

addChild(black);
addChild(next_btn);
}

function nextSection(e:MouseEvent):void{

//currentSection out
TweenLite.to(bars[currentSection], speed,  {y:even.offScreen});
TweenLite.to(bars[currentSection+1], speed,  {y:odd.offScreen});

//new section in
currentSection = (currentSection+2) % bars.length;
trace(currentSection);


TweenMax.fromTo(bars[currentSection], speed,  {y:initY}, {y:even.onScreen});
TweenMax.fromTo(bars[currentSection+1], speed,  {y:initY}, {y:odd.onScreen});

}

next_btn.addEventListener(MouseEvent.CLICK, nextSection);


createBars();

 

this should give you an idea of one way to approach this.

of course nextSection could be called with a Timer.

 

 

 

upAndup.zip

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