Posted By

okhy on 09/14/11


Tagged

time timeline line enter frame rewind manipulation backward


Versions (?)

Timeline Manipulation


 / Published in: ActionScript 3
 

  1. /* to move playhead frame by frame, forward */
  2. MovieClip.prototype.playTo = function(frameNum:Number){
  3. this.frameNum = frameNum;
  4. this.addEventListener(Event.ENTER_FRAME, playLoop);
  5. }
  6. function playLoop(e:Event):void{
  7. if(e.currentTarget.currentFrame < e.currentTarget.frameNum){
  8. e.currentTarget.nextFrame();
  9. }else if(e.currentTarget.currentFrame == e.currentTarget.frameNum){
  10. e.currentTarget.removeEventListener(Event.ENTER_FRAME, playLoop);
  11. e.currentTarget.stop();
  12. }
  13. }
  14.  
  15. /* to move playhead frame by frame, backward */
  16. MovieClip.prototype.rewindTo = function(frameNum:Number){
  17. this.frameNum = frameNum
  18. this.addEventListener(Event.ENTER_FRAME, rewindLoop);
  19. }
  20. function rewindLoop(e:Event):void{
  21. if(e.currentTarget.currentFrame > e.currentTarget.frameNum){
  22. e.currentTarget.prevFrame();
  23. }else if(e.currentTarget.currentFrame == e.currentTarget.frameNum){
  24. e.currentTarget.removeEventListener(Event.ENTER_FRAME, rewindLoop);
  25. e.currentTarget.stop();
  26. }
  27. }
  28.  
  29. /*
  30. usage:
  31.  
  32. MC_withTimeline, contain more than 1 frame and has stop() at frame number 1.
  33. ----------------------------------------------------------------------------
  34. MC_withTimeline.addEventListener(MouseEvent.ROLL_OVER, onRoll);
  35. MC_withTimeline.addEventListener(MouseEvent.ROLL_OUT, onOut);
  36.  
  37. function onRoll(e:MouseEvent):void{
  38. e.currentTarget.playTo(e.currentTarget.totalFrames);
  39. }
  40.  
  41. function onOut(e:MouseEvent):void{
  42. e.currentTarget.rewindTo(1);
  43. }
  44.  
  45. */

Report this snippet  

You need to login to post a comment.