Jump to content
Search Community

Nested Timeline Problem

mrkos67 test
Moderator Tag

Recommended Posts

Do nested timelines have to have the same parent, i.e. can my Document Class have a timeline, and append/insert a child object's timeline? Because right now, I can't seem to get it working. Here's a breakdown of my code:

 

	//-------------------------------------------------------------------------------------------------------------------------------------
	...
		_timeline = new TimelineMax();
		for( $i = 0; $i < $aifs.length; $i++ )
		{
			aif = $aifs[$i];
			var tlmAIF:TimelineMax = new TimelineMax();
			if( aif.timeline )
				tlmAIF.insert( aif.timeline, 0 );
			tlmAIF.insert( TweenLite.to( aif, .5, { alpha:1 } ), 0 );
			tlmAIF.insert( TweenLite.to( aif, $transTime, { alpha:0 } ), 3.5 );
			_timeline.append( tlmAIF, -$transTime );
		}
	...

 

The problem comes when doing the tlmAIF.insert( ... ) on the aif.timeline, even though aif.timeline is not null and it will play using other means by changing the previous code to use an onStart function like so:

 

	//-------------------------------------------------------------------------------------------------------------------------------------
	...
		_timeline = new TimelineMax();
		for( $i = 0; $i < $aifs.length; $i++ )
		{
			aif = $aifs[$i];
			var tlmAIF:TimelineMax = new TimelineMax( {onStart:onStart_aif, onStartParams:[ aif ] } );
			tlmAIF.insert( TweenLite.to( aif, .5, { alpha:1 } ), 0 );
			tlmAIF.insert( TweenLite.to( aif, $transTime, { alpha:0 } ), 3.5 );

			_timeline.append( tlmAIF, -$transTime );
		}
	...
	//-------------------------------------------------------------------------------------------------------------------------------------
	private function onStart_aif( aif:AnimatedImageFrame ):void
	{
		aif.timeline.play();
	}

 

However, I want all animations to be within the main timeline so i can play/pause/seek accordingly. Any insight would be much appreciated. Thanks.

Link to comment
Share on other sites

is aif.timeline paused when it is created?

 

I see the seek/play/pause issue you are having with your onStart solution, but I'm wondering why aif.timeline needs to have its play() method called at all.

I would think it would start playing when _timeline reaches the point the aif.timeline was inserted.

 

just to see 1 way of adding child-object timelines to a master timeline, take a quick peek at the source files for this tutorial:

http://www.snorkl.tv/2011/05/real-world ... ase-study/

 

each child object (slide) has a method that returns a TimelineLite or TimelineMax.

 

when the master timeline is built it look something like

 

_timeline.append( slide1.animateIn() )
_timeline.append( slide2.animateOut() )
_timeline.append( slide3.animateIn() )

 

-----

 

the slide1 object might have code that looks like:

 

public function animateIn():TimelineLite {
		var tl:TimelineLite = new TimelineLite();
		tl.insert(new TweenLite(this, .5, {autoAlpha:1}));
                       tl.insert(TweenLite.to(this.header_mc, 1, {x:300});
		tl.insert(TweenLite.from(this, 1, {x:"400", blurFilter:{blurX:50}}));
		return tl;
	}

	public function animateOut():TimelineLite {
		var tl:TimelineLite = new TimelineLite();
		tl.append(new TweenLite(this, .5, {autoAlpha:0}));
                        tl.insert(TweenLite.to(this.header_mc, 1, {x:900});
		tl.insert(TweenLite.to(this, 1, {x:"-600", blurFilter:{blurX:80}}));
		return tl;
	}

 

the take away here is that the child timeline's are created the instant they are appended into the main _timeline, and they don't need to be paused, and they play when they are supposed to.

 

perhaps this approach will suit your situation.

 

c

Link to comment
Share on other sites

it is paused when it's created because it's being created earlier in the function. i didn't even think of that. that's why it isn't playing. i commented that line of code, and the first aif plays but not the successive ones (they actually are, but at the same time as the others because they're all created in the same FOR loop earlier).

 

so yeah, now the question is why the main timeline isn't triggering/playing each child timeline when it reaches it?

Link to comment
Share on other sites

so i found this thread (viewtopic.php?f=1&t=1585) and apparently what i'm experiencing isn't a bug, but it's the way Greensock intended.

 

Greensock: will there be an update to the timeline classes to include some sort of variable to override this behavior? i could see this being very handy.

 

carl: thanks for your suggestion, i've modified my code to do something similar to what you've outlined, and it works perfectly.

Link to comment
Share on other sites

in essence the paused property of a timeline handles whether or not it plays while its parent is playing.

 

if you unpause your aif.timeline immediately prior to insertion in the _timeline you should be fine.

 

condsider the following example:

 

import com.greensock.*;

var tl:TimelineMax = new TimelineMax();


var tl2:TimelineMax = new TimelineMax({paused:true});
tl2.append(TweenMax.to(mc2, 2, {x:350}));


tl.append(TweenMax.to(mc1,4,{x:350}));


tl2.paused = false;
tl.insert(tl2, 2);

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