lanemiller
lanemiller

Reputation: 1

AS3 Tween Easing

I've set a hover on and hover off tween to a certain element in flash, where you hover over an element, and an informational window slides in off the bottom, and when you hover off it slides back. Hover, when I hover off before the hover on animation is over, the given object jumps to the end of the first animation and back. How do I make the animation ease in and out when someone hovers over something?

function initialPlacement()
{
    block1.x = (-814);
    block1.y = (stage.stageHeight - 100);
}

initialPlacement();

tension.addEventListener(MouseEvent.ROLL_OVER,hover1);
tension.addEventListener(MouseEvent.ROLL_OUT,off1);

function hover1(event:MouseEvent):void{
    hover1tween.start();
}

var hover1tween:Tween = new Tween(block1,"x",Regular.easeOut,(0-block1.width),0,30,false);

hover1tween.stop();

function off1(event:MouseEvent):void{
    off1tween.start();
}

var off1tween:Tween = new Tween(block1,"x",Regular.easeInOut,0,(0-block1.width),30,false);
off1tween.stop();

initialPlacement();

Upvotes: 0

Views: 2700

Answers (1)

IQAndreas
IQAndreas

Reputation: 8468

I believe the easiest way would be using the "continueTo" function which will send the tween in a new direction from where it is rather than restart it.

function initialPlacement()
{
    block1.x = (-814);
    block1.y = (stage.stageHeight - 100);

    block1tween = new Tween(block1,"x",Regular.easeInOut,(0-block1.width),0,30,false);
    block1tween.stop();
}

var block1tween:Tween;
initialPlacement();

tension.addEventListener(MouseEvent.ROLL_OVER,hover1);
tension.addEventListener(MouseEvent.ROLL_OUT,off1);

function hover1(event:MouseEvent):void{
    block1tween.continueTo(0, 30);
}

function off1(event:MouseEvent):void{
    block1tween.continueTo((0-block1.width),30);
}

Does that meet your needs? Otherwise you could replace the tween with a new one each passing in the current coordinates in the "begin" parameter of the Tween, but I find just using "continueTo()" is much easier and cleaner.

Upvotes: 1

Related Questions