Return to Snippet

Revision: 53386
at November 21, 2011 15:31 by okhy


Updated Code
/**
 * VERSION: Early
 * DATE: 2011-11-15
 * AS3
 * TimelineTween, a class to simplify rollOver and rollOut event of a MovieClip based button.
 **/
package com.tl {
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class TimelineTween extends MovieClip{
		
		public function TimelineTween(object:MovieClip) {
			object.addEventListener(MouseEvent.ROLL_OVER, onRollover);
			object.addEventListener(MouseEvent.ROLL_OUT, onRollout);
		}

		/* Events */
		private function onRollover(me:MouseEvent):void{
			playTo(me.currentTarget, me.currentTarget.totalFrames);
		}
		private function onRollout(me:MouseEvent):void{
			rewindTo(me.currentTarget, 1);
		}

		/* Public functions */
		public static function onRollAndOut(object:MovieClip):TimelineTween{
			return new TimelineTween(object);
		}
		
		public static function playTo(object:MovieClip, frameNum:Number){
			object.types = "number";
			object.frameNum = frameNum;			
			object.addEventListener(Event.ENTER_FRAME, playLoop);
		}
		
		public static function rewindTo(object:MovieClip, frameNum:Number){
			object.types = "number";
			object.frameNum = frameNum;
			object.addEventListener(Event.ENTER_FRAME, rewindLoop);
		}
		
		public static function rollToLabel(object:MovieClip, label:String):void{
			object.types = "label";
			object.frameLabel = label;
			object.addEventListener(Event.ENTER_FRAME, playLoop);
		}

		public static function rewindToLabel(object:MovieClip, label:String):void{
			object.types = "label";
			object.frameLabel = label;
			object.addEventListener(Event.ENTER_FRAME, rewindLoop);
		}
		
		/* Enterframe for mouse roll over event - start */
		private function playLoop(e:Event):void{
			if(e.currentTarget.types == "number"){
				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();
				}
			}else if(e.currentTarget.types == "label"){
				if(e.currentTarget.currentFrameLabel == e.currentTarget.frameLabel){
					e.currentTarget.removeEventListener(Event.ENTER_FRAME, playLoop);
					e.currentTarget.stop();
				}else{
					e.currentTarget.nextFrame();
				}
			}
		}
		/* Enterframe for mouse roll over event - end */
		
		
		/* Enterframe for mouse roll out event - start */		
		private function rewindLoop(e:Event):void{
			if(e.currentTarget.types == "number"){
				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();
				}
			}else if(e.currentTarget.types == "label"){
				if(e.currentTarget.currentFrameLabel == e.currentTarget.frameLabel){
					e.currentTarget.removeEventListener(Event.ENTER_FRAME, rewindLoop);
					e.currentTarget.stop();
				}else{
					e.currentTarget.prevFrame();
				}
			}
		}
		/* Enterframe for mouse roll out event - end */	

	}
}

/*
How To use it.

Create one way classic tween animation and put stop(); in the first frame.
Then, put this script outside your movie clip

// Standard use
import com.tl.TimelineTween;

var movieClipButton:MovieClip = new MovieClip();
TimelineTween.onRollAndOut(movieClipButton);

// Custom use
import com.tl.TimelineTween;

var movieClipButton:MovieClip = new MovieClip();
// Forward use
TimelineTween.playTo(movieClipButton, 24); // playTo(object:MovieClip, frameNumber:Number);
// Backward use
TimelineTween.rewindTo(movieClipButton, 1); // rewindTo(object:MovieClip, frameNumber:Number);
// Forward use with label
TimelineTween.playTo(movieClipButton, "end_of_mc"); // playTo(object:MovieClip, label:String);
// Backward use with label
TimelineTween.rewindTo(movieClipButton, "beginning_of_mc"); // rewindTo(object:MovieClip, label:String);

*/

Revision: 53385
at November 21, 2011 15:28 by okhy


Initial Code
/**
 * VERSION: Early
 * DATE: 2011-11-15
 * AS3
 * TimelineTween, a class to simplify rollOver and rollOut event of a MovieClip based button.
 **/
package com.tl {
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class TimelineTween extends MovieClip{
		
		public function TimelineTween(object:MovieClip) {
			object.addEventListener(MouseEvent.ROLL_OVER, onRollover);
			object.addEventListener(MouseEvent.ROLL_OUT, onRollout);
		}

		/* Events */
		private function onRollover(me:MouseEvent):void{
			playTo(me.currentTarget, me.currentTarget.totalFrames);
		}
		private function onRollout(me:MouseEvent):void{
			rewindTo(me.currentTarget, 1);
		}

		/* Public functions */
		public static function onRollAndOut(object:MovieClip):TimelineTween{
			return new TimelineTween(object);
		}
		
		private function playTo(object:MovieClip, frameNum:Number){
			object.types = "number";
			object.frameNum = frameNum;			
			object.addEventListener(Event.ENTER_FRAME, playLoop);
		}
		
		public function rewindTo(object:MovieClip, frameNum:Number){
			object.types = "number";
			object.frameNum = frameNum;
			object.addEventListener(Event.ENTER_FRAME, rewindLoop);
		}
		
		public static function rollToLabel(object:MovieClip, label:String):void{
			object.types = "label";
			object.frameLabel = label;
			object.addEventListener(Event.ENTER_FRAME, playLoop);
		}

		public static function rewindToLabel(object:MovieClip, label:String):void{
			object.types = "label";
			object.frameLabel = label;
			object.addEventListener(Event.ENTER_FRAME, rewindLoop);
		}
		
		/* Enterframe for mouse roll over event - start */
		private function playLoop(e:Event):void{
			if(e.currentTarget.types == "number"){
				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();
				}
			}else if(e.currentTarget.types == "label"){
				if(e.currentTarget.currentFrameLabel == e.currentTarget.frameLabel){
					e.currentTarget.removeEventListener(Event.ENTER_FRAME, playLoop);
					e.currentTarget.stop();
				}else{
					e.currentTarget.nextFrame();
				}
			}
		}
		/* Enterframe for mouse roll over event - end */
		
		
		/* Enterframe for mouse roll out event - start */		
		private function rewindLoop(e:Event):void{
			if(e.currentTarget.types == "number"){
				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();
				}
			}else if(e.currentTarget.types == "label"){
				if(e.currentTarget.currentFrameLabel == e.currentTarget.frameLabel){
					e.currentTarget.removeEventListener(Event.ENTER_FRAME, rewindLoop);
					e.currentTarget.stop();
				}else{
					e.currentTarget.prevFrame();
				}
			}
		}
		/* Enterframe for mouse roll out event - end */	

	}
}

/*
How To use it.

Create one way classic tween animation and put stop(); in the first frame.
Then, put this script outside your movie clip

// Standard use
import com.tl.TimelineTween;

var movieClipButton:MovieClip = new MovieClip();
TimelineTween.onRollAndOut(movieClipButton);

// Custom use
import com.tl.TimelineTween;

var movieClipButton:MovieClip = new MovieClip();
// Forward use
TimelineTween.playTo(movieClipButton, 24); // playTo(object:MovieClip, frameNumber:Number);
// Backward use
TimelineTween.rewindTo(movieClipButton, 1); // rewindTo(object:MovieClip, frameNumber:Number);
// Forward use with label
TimelineTween.playTo(movieClipButton, "end_of_mc"); // playTo(object:MovieClip, label:String);
// Backward use with label
TimelineTween.rewindTo(movieClipButton, "beginning_of_mc"); // rewindTo(object:MovieClip, label:String);

*/

Initial URL

                                

Initial Description
Class version of TimelineManipulation.

Initial Title
Timeline Manipulation

Initial Tags
line

Initial Language
ActionScript 3