Search code examples
actionscript-3tween

How to know when the yoyo will finish?


I want show a trace("test") at the end of the yoyo

How to know when the yoyo will finish?

I'm using AS3

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var myTween = new Tween(my_mc, "x", Strong.easeInOut, 100,300, 1, true);

myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);

function onFinish(e:TweenEvent):void {
    myTween.yoyo();
}

Solution

  • import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    
    var myTween = new Tween(my_mc, "x", Strong.easeInOut, 100,300, 1, true);
    myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
    var yoyoCounter:uint;
    
    function onFinish(e:TweenEvent):void {
        if(yoyoCounter < 1)
        {
            myTween.yoyo();
            ++yoyoCounter;
        }
        else
        {
            myTween.removeEventListener(TweenEvent.MOTION_FINISH, onFinish);
            trace("test");
        }
    }
    

    Rob