Tween A Number with GreenSock’s Tweening Class

I am going to give you a little example on how to tween a number. This example can be used with other tweening classes as well like Caurina’s Tweener.

Pay attention that the variable we want to tween needs to be public otherwise you’ll get an error compiling the code.

We are going define a variable as an Object. This object will hold a value. The tweener will tween this object’s value.

public var my_number :Object  =  { value: 0 };
TweenLite.to( this.my_number,  .5, { value: 100 , onUpdate:function(){ trace (this.value); } } )

 

Mouse Follower with Angle Rotation

First create an arrow Movie Clip ( make sure the tip of the arrow is on the register point of the Movie Clip ) and add it to the scene and name it “arrow”.

You will also need Caurina Tweener ( but other tweeners can be used also ).


import caurina.transitions.Tweener;

stage.addEventListener(MouseEvent.MOUSE_MOVE, Moving, false, 0, true);

function Moving(e:Event):void
{
var X:Number =  mouseX - arrow.x;
var Y:Number = (mouseY - arrow.y) * -1;

var angle:Number = Math.atan(Y/X)/(Math.PI/180);

Tweener.addTween(arrow ,{x :mouseX, y: mouseY, time:2});

if (X<0) { 		angle += 180; 	} 	

if (Y>=0 && Y<0) {  angle += 360;}

arrow.rotation = (angle*-1) + 90;

}