Return to Snippet

Revision: 51107
at September 14, 2011 16:38 by okhy


Initial Code
/* 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);
}

*/

Initial URL


Initial Description


Initial Title
Timeline Manipulation

Initial Tags
line

Initial Language
ActionScript 3