Jump to content
Search Community

Problems replaying TimelineMax (what can be replayed?)

cerulean test
Moderator Tag

Recommended Posts

Wrote a long animation with multiple nested timelines and many children (100 +/-). Then did timeline.replay() and it replayed magically! Amazing!

 

But I ran into an instance where some things don't 'play nice' -- that is I need to perform some manipulations of graphics on screen and added callbacks like this

 

    private function positionBoxes():void {
       // add grey background to big box
       _superBigBox.addChild(_grey);
       // add 2b to big box
       _superBigBox.addChild(_box2b);
       // put 1a box offscreen left
       _box1a.x = -_box1a.width;
       _superBigBox.addChild(_box1a);
   }

   private function repositionBoxes():void {
       // now need to swap box 2a for 2b
       _box2a.x = _box2b.x;
       _box2a.y = _box2b.y;
       _superBigBox.addChild(_box2a);
       // put box2b below box2a
       _box2b.y += _box2a.height;
   }

 

Works fine the first time through, but not on replay.

 

I believe the answer is to position using 0 length tweens, with immediateRender == false, but how does one handle non-tweenable actions such as adding children, etc?

 

That is, are some actions, even when added to the timeline through addCallback, not entirely PART of the timeline, and thus not reversable, replayable? What am I missing?

Link to comment
Share on other sites

yes, that is the expected behavior.

 

if you use a callback to modify an object's properties outside of the TimelineMax, that modification isn't going to undo itself when the TimelineMax plays again or reverses.

 

take the following example:

 

var tl:TimelineMax = new TimelineMax({repeat:5});


tl.append(TweenMax.to(mc, 1, {x:400}));
tl.addCallback(fade, tl.duration);
tl.append(TweenMax.to(mc, 1, {y:400}));



function fade():void{
mc.alpha= .5
}

 

once the fade callback gets fired, the mc will have an alpha of .5 on all subsequent plays.

 

when you restart() your timelinemax you can run your own initialization function that resets all the stuff you modified outside of the TimelineMax.

 

if you are doing things in reverse, it would be possible yet complicated to add callbacks that perform tasks only if the TimelineMax is reversed.

 

 

[edit] i see you just figured this out for yourself. good job![/edit]

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