/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* to move playhead frame by frame, forward */ MovieClip.prototype.playTo = function(frameNum:Number){ this.frameNum = frameNum; this.addEventListener(Event.ENTER_FRAME, playLoop); } function playLoop(e:Event):void{ if(e.currentTarget.currentFrame < e.currentTarget.frameNum){ e.currentTarget.nextFrame(); }else if(e.currentTarget.currentFrame == e.currentTarget.frameNum){ e.currentTarget.removeEventListener(Event.ENTER_FRAME, playLoop); e.currentTarget.stop(); } } /* to move playhead frame by frame, backward */ MovieClip.prototype.rewindTo = function(frameNum:Number){ this.frameNum = frameNum this.addEventListener(Event.ENTER_FRAME, rewindLoop); } function rewindLoop(e:Event):void{ if(e.currentTarget.currentFrame > e.currentTarget.frameNum){ e.currentTarget.prevFrame(); }else if(e.currentTarget.currentFrame == e.currentTarget.frameNum){ e.currentTarget.removeEventListener(Event.ENTER_FRAME, rewindLoop); e.currentTarget.stop(); } } /* usage: MC_withTimeline, contain more than 1 frame and has stop() at frame number 1. ---------------------------------------------------------------------------- MC_withTimeline.addEventListener(MouseEvent.ROLL_OVER, onRoll); MC_withTimeline.addEventListener(MouseEvent.ROLL_OUT, onOut); function onRoll(e:MouseEvent):void{ e.currentTarget.playTo(e.currentTarget.totalFrames); } function onOut(e:MouseEvent):void{ e.currentTarget.rewindTo(1); } */