Jump to content
Search Community

TimelineMax paused- no onComplete with slider

mintervals test
Moderator Tag

Recommended Posts

Hi I have a timelineMax paused that I can scroll with a slider. I need to have functions called when certain points of the timeline are hit. The below code only works if the timeline isn't paused. What am I missing, thanks so much!

 

 

import com.greensock.*;

import com.greensock.easing.*;

 

import fl.controls.Slider;

import fl.events.SliderEvent;

 

var mainTimeLine:TimelineMax;

mainTimeLine = new TimelineMax({paused:true});

 

mainTimeLine.insert(TweenMax.to(mc1, 3, {y:"50", delay:0, onComplete:mc1Call}));

mainTimeLine.insert(TweenMax.to(mc2, 3, {y:"50", delay:3, onComplete:mc2Call}));

mainTimeLine.insert(TweenMax.to(mc3, 3, {y:"50", delay:6, onComplete:mc3Call}));

 

slider.liveDragging = true;

slider.snapInterval = 0.01;

slider.enabled = true;

slider.minimum = 0;

slider.maximum = mainTimeLine.totalDuration;

 

 

slider.addEventListener(SliderEvent.THUMB_DRAG, thumbDragHandler);

 

 

function thumbDragHandler(e:SliderEvent):void

{

mainTimeLine.gotoAndStop(e.value);

 

}

 

 

function mc1Call():void{

 

trace("mc1Call");

 

}

 

 

function mc2Call():void{

 

trace("mc2Call");

 

}

 

 

function mc3Call():void{

 

trace("mc3Call");

 

}

Link to comment
Share on other sites

By default, gotoAndStop() suppresses the events (callbacks) when it moves the virtual playhead (think of it like picking up the needle on a record player and dropping it into the new position instead of dragging the needle across the record). But you can certainly change that behavior if you prefer by setting the suppressEvents parameter to false, like:

 

mainTimeLine.gotoAndStop(e.value, false);

 

See the docs at http://greensock.com...ml#gotoAndStop()

Link to comment
Share on other sites

Yep, that's how it works. I used the following code with v12 and it traced correctly ("f1, f2, f3, f3, f2, f1"):

 

var tl:TimelineLite = new TimelineLite({paused:true});
tl.call(f1);
tl.call(f2, null, 1);
tl.call(f3, null, 1);

tl.gotoAndStop(2, false);
tl.gotoAndStop(0, false);

function f1():void {
   trace("f1");
}

function f2():void {
   trace("f2");
}

function f3():void {
   trace("f3");
}

Link to comment
Share on other sites

Mintervale,

 

Just want to point out that Jack is using call() and you are using onComplete callbacks on individual tweens.

When a timeline is reversing or is forced backwards, the onComplete's don't fire.

 

consider the following 2 timeline's that are set to play forward and then backward.

 

var tl:TimelineMax = new TimelineMax({repeat:1, yoyo:true});
tl.append(TweenLite.to(mc, 1, {x:100, onComplete:trace, onCompleteParams:[1]}));
tl.append(TweenLite.to(mc, 1, {y:100, onComplete:trace, onCompleteParams:[2]}));
tl.append(TweenLite.to(mc, 1, {x:200, onComplete:trace, onCompleteParams:[3]}));

//output 1, 2, 3
//no traces when it is reversed on the yoyo repeat.

 

call() is locked to a point in time and runs independent of any tweens completing

var tl:TimelineMax = new TimelineMax({repeat:1, yoyo:true});
tl.append(TweenLite.to(mc, 1, {x:100}));
tl.call(trace, [1]);
tl.append(TweenLite.to(mc, 1, {y:100}));
tl.call(trace, [2]);
tl.append(TweenLite.to(mc, 1, {x:200}));
tl.call(trace,  [3]);
//output 1, 2, 3, 2, 1
//traces in both directions

 

 

also, if you pause them and try GreenSock's maneuver on them

 

var tl:TimelineMax = new TimelineMax({paused:true});

...tweens


tl.gotoAndStop(tl.duration(), false);
tl.gotoAndStop(0, false);

the first timeline will output 1, 2, 3

the second one will output 1, 2, 3, 3, 2, 1

 

hopefully this helps clear up any confusion if there was any.

 

-c

  • Like 1
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...