Jump to content
Search Community

TimelineMax: restarting from stopped point

isaballoon test
Moderator Tag

Recommended Posts

How is it possible to record the 'stop' position (derived from a CLICK of 'stop' button) and have it continue from that point on restart (toggling a 'startStop' button). Question I have is in coding of the 'startStop' handler. Here's what I've got (I haven't included the variables set up as a way of keeping it simple):

 


start.addEventListener(MouseEvent.CLICK, animate);
startStop.addEventListener(MouseEvent.CLICK, startStop);

private function animate(e:MouseEvent):void {
isMoving = true;
start.removeEventListener(MouseEvent.CLICK, animate);
start.visible = false;

tl = new TimelineMax({repeat:-1});
tl.append(TweenMax.to(ball, .4, {x:twoXPos, ease:Linear.easeNone}));
tl.append(TweenMax.to(ball, .1, {y:threeYPos, ease:Linear.easeNone}));
tl.append(TweenMax.to(ball, .4, {x:fourXPos, ease:Linear.easeNone}));
tl.append(TweenMax.to(ball, .1, {y:oneYPos, ease:Linear.easeNone}));
}

private function startStop(e:MouseEvent):void {
if(isMoving) {
       tl.pause();
       cp = tl.currentProgress // recording current progress
isMoving = false;
} else {
tl.restart();

       isMoving = true;
}
}

 

Any help is greatly appreciated.

Link to comment
Share on other sites

figured it out. Here's what works:

start.addEventListener(MouseEvent.CLICK, animate);
startStop.addEventListener(MouseEvent.CLICK, startStop);

private function animate(e:MouseEvent):void {
  isMoving = true;
  start.removeEventListener(MouseEvent.CLICK, animate);
  start.visible = false;

  tl = new TimelineMax({repeat:-1});
  tl.append(TweenMax.to(ball, .4, {x:twoXPos, ease:Linear.easeNone}));
  tl.append(TweenMax.to(ball, .1, {y:threeYPos, ease:Linear.easeNone}));
  tl.append(TweenMax.to(ball, .4, {x:fourXPos, ease:Linear.easeNone}));
  tl.append(TweenMax.to(ball, .1, {y:oneYPos, ease:Linear.easeNone}));
}

private function startStop(e:MouseEvent):void {
  if(isMoving) {
       tl.pause();
       ct = tl.currentTime // recording current time
  isMoving = false;
} else {
       tl.gotoAndPlay(ct); // playing from that current time
       isMoving = true;
  }
}

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