Flash AS3 Slider Tween using Mouse Position

First here is the code without the easing effect. I used the stage as the view scroller width and added an Enter Frame event to the stage for movement.

var scrollSize:int = stage.stageWidth;
var contentSize:int = box.width;
var outOfViewSize:int = contentSize-scrollSize;
var divideBy:Number = scrollSize/outOfViewSize;
var moveToPos:int;
stage.addEventListener(Event.ENTER_FRAME, slideMC);
 
function slideMC(event:Event):void
{
	moveToPos = mouseX/divideBy;
	trace("scrollSize:"+scrollSize+" contentSize:"+contentSize+" / outOfViewSize:"+outOfViewSize+" / divideBy:"+divideBy+" / moveToPos:"+moveToPos);
	box.x = -moveToPos ;
}

Now here is the above code with tweening using the Tweener class.

///////////////// IMPORTS ////////////
import caurina.transitions.Tweener;
 
var scrollSize:int = stage.stageWidth;
var contentSize:int = box.width;
var outOfViewSize:int = contentSize-scrollSize;
var divideBy:Number = scrollSize/outOfViewSize;
var moveToPos:int;
stage.addEventListener(Event.ENTER_FRAME, slideMC);
 
function slideMC(event:Event):void
{
	moveToPos = mouseX/divideBy;
	trace("scrollSize:"+scrollSize+" contentSize:"+contentSize+" outOfViewSize:"+outOfViewSize+" / divideBy:"+divideBy+" / moveToPos:"+moveToPos);
	Tweener.addTween(box,{x:-moveToPos,time:5});
}

You may also like...

Leave a Reply