Usefull timeline manipulation functions


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //will stop 'play', 'gotoAndPlay' and 'rewind', 'gotoAndRewind' functions
  2. MovieClip.prototype.stopAll = function () {
  3. delete this.onEnterFrame;
  4. this.stop();
  5. }
  6.  
  7. //will stop 'rewind', 'gotoAndRewind' functions
  8. MovieClip.prototype.stopRewind = function () {
  9. delete this.onEnterFrame;
  10. }
  11.  
  12. //will play the timeline backwards and continal to loop until 'stopAll', 'stopRewind' or 'pause' are called
  13. //note: the 'rewind' function will cancel the 'play' function BUT the 'play' function will not cancel the 'rewind' function
  14. //you must call 'stopAll' or 'stopRewind' before using 'play' when your timeline is playing backwards
  15. MovieClip.prototype.rewind = function () {
  16. this.stop();
  17. this.onEnterFrame = function () {
  18. if (this._currentframe > 0) {
  19. this.prevFrame ();
  20. } else {
  21. this.gotoAndStop (this._totalframes);
  22. }
  23. }
  24. }
  25.  
  26. //will goto the specified frame and play the timeline backwards and continal to loop until 'stopAll', 'stopRewind' or 'pause' are called
  27. MovieClip.prototype.gotoAndRewind = function (frame) {
  28. this.gotoAndStop (frame);
  29. this.rewind();
  30. }
  31.  
  32. //will pause the timeline for the specified amount of time. will always play forwards when the pause has finished
  33. MovieClip.prototype.pause = function (time) {
  34. delete this.onEnterFrame;
  35. secondsToPause = time;
  36. pauseInt = setInterval (this, "restart", secondsToPause * 1000);
  37. }
  38.  
  39. restart = function () {
  40. clearInterval (pauseInt);
  41. play();
  42. }

URL: http://www.flashgroup.net/forum/showthread.php?t=2323

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.