Skip to main content
Known Participant
December 5, 2014
Answered

How do I make a scrubber for an animation?

  • December 5, 2014
  • 3 replies
  • 1190 views

I created an animation on how a 4 stroke motor works and want to be able to play, stop and scrub through the animation. All i can find on the internet is scrubbing for video/audio. Can someone help. Thanks

Correct answer rezun8

the easiest way I can think to do it would be to export the animation as a video (take your pick) and then open in a video program for final export, that way the user can scrub as needed.

if it needs to be done within Flash this might help: http://www.gotoandlearnforum.com/viewtopic.php?t=24015

3 replies

mcaloney_d
Inspiring
December 8, 2014

Let me know if you need help with the scrub bar and scrubBar handle.

svendkrAuthor
Known Participant
December 9, 2014

Got it all to work,  thanks again.

mcaloney_d
Inspiring
December 7, 2014

I did not write this. It will play and scrub the timeline of a movieclip (instance name: MCflow) on the stage.

You will need an MC for the scrub bar (instance name scrubBarMC) and the handle (instance name scrubHandleMC) that users will click and drag. Select both of these MCs, create a new MC and give it an instance name of scrubberMC

Place the button component on the stage and give it an instance name of toggleBtnMC. Add a dynamic text field and give it an instance name frameTxtMC. The text field will display the frame number as the movieclip plays or while you are scrubbing the timeline.

//code for movieclip scrubber

var animLengthMC : int = MCflow.totalFrames;

var leftBoundMC : Number = scrubberMC.scrubBarMC.x;

var rightBoundMC : Number = scrubberMC.scrubBarMC.x + scrubberMC.scrubBarMC.width;

var dragBoundMC : Rectangle = new Rectangle(leftBoundMC, scrubberMC.scrubHandleMC.y, scrubberMC.scrubBarMC.width, 0);

var calcWidthMC : Number = scrubberMC.scrubBarMC.width / animLengthMC;

var animPlayingMC : Boolean = false;

MCflow.gotoAndStop(1);

frameTxtMC.text = String(MCflow.currentFrame);

scrubberMC.scrubHandleMC.x = leftBoundMC;

scrubberMC.scrubHandleMC.buttonMode = true;

scrubberMC.scrubHandleMC.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseEventsMC);

toggleBtnMC.label = "PLAY";

toggleBtnMC.addEventListener(MouseEvent.CLICK, togglePlayMC);

function handleMouseEventsMC(evt:MouseEvent):void

{

  switch(String(evt.type)) {

  case MouseEvent.MOUSE_DOWN:

  scrubberMC.scrubHandleMC.startDrag(false, dragBoundMC);

  stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseEventsMC);

  MCflow.addEventListener(Event.ENTER_FRAME, scrubMovieMC);

  break;

  case MouseEvent.MOUSE_UP:

  scrubberMC.scrubHandleMC.stopDrag();

  stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseEventsMC);

  MCflow.removeEventListener(Event.ENTER_FRAME, scrubMovieMC);

  break;

  }

}

function scrubMovieMC(evt:Event):void

{

  var scrubPosMC : int = scrubberMC.scrubHandleMC.x;

  var gotoFrameMC : int = Math.ceil(scrubPosMC / calcWidthMC);

  MCflow.gotoAndStop(gotoFrameMC);

  frameTxtMC.text = String(MCflow.currentFrame);

}

function togglePlayMC(evt:MouseEvent):void

{

  if (!animPlayingMC) {

  MCflow.play();

  animPlayingMC = true;

  toggleBtnMC.label = "PAUSE";

  scrubberMC.addEventListener(Event.ENTER_FRAME, updateScrubberMC);

  // DISABLE SCRUBBER INTERACTION WHILE ANIMATION PLAYS

  scrubberMC.mouseChildren = false;

  } else {

  MCflow.stop();

  animPlayingMC = false;

  toggleBtnMC.label = "PLAY";

  scrubberMC.removeEventListener(Event.ENTER_FRAME, updateScrubberMC);

  // ENABLE SCRUBBER INTERACTION AFTER ANIMATION STOPS

  scrubberMC.mouseChildren = true;

  }

}

function updateScrubberMC(evt:Event):void

{

  var percentMC : Number = MCflow.currentFrame / animLengthMC;

  scrubberMC.scrubHandleMC.x = percentMC * scrubberMC.scrubBarMC.width;

  frameTxtMC.text = String(MCflow.currentFrame);

}

svendkrAuthor
Known Participant
December 8, 2014

Thanks. So will this work on a, or how do i make the code work on a timeline that doesn't have embedded movie clips? It is just a movie that is going to be about 300 frames long.

mcaloney_d
Inspiring
December 8, 2014

I usually save my fla as a different name so I have a backup copy should something go wrong.

My suggestion is to draw a simple square and make that a movieclip. On the main timeline Shift - Select all of the Layers for your engine animation (not your new square mc), go to Edit - Timeline - Copy Layers.

Open the square movieclip, delete the square then Edit - Timeline - Paste Layers. Now you have a movieclip that can be placed on the stage and assigned an instance name.

rezun8
rezun8Correct answer
Inspiring
December 5, 2014

the easiest way I can think to do it would be to export the animation as a video (take your pick) and then open in a video program for final export, that way the user can scrub as needed.

if it needs to be done within Flash this might help: http://www.gotoandlearnforum.com/viewtopic.php?t=24015

svendkrAuthor
Known Participant
December 5, 2014

Perfect! option 2 was what i was looking for and option 1 is a good idea too. Thanks for your help