[Solved]Tween onComplete is running after destroy

  • In my flxsubstate's create I have this tween which has onComplete: startModalBGTween. If I open and close the substate quickly it gets an error in vartween.hx in its object==null throw [Fault] exception, information=Cannot tween variables of an object that is null. I put a trace in my destroy function, startmodalBGTween function, and startCloseTween function and I get this error when startmodal or startclose have their trace message after the destroy trace. Which I imagine means the onComplete is being called still after destroy. I am not sure how to fix this though...

    FlxTween.tween(alphaBlackBG, { alpha: 1 }, .15, { type: FlxTween.ONESHOT, onComplete: startModalBGTween } );

    private function startModalBGTween(twn:FlxTween):Void
    FlxTween.tween(modalBGImage, { y: modalYPOS }, .6, { type: FlxTween.ONESHOT, onComplete: startCloseTween});

    private function startCloseTween(twn:FlxTween):Void {
    	closeXButton.scale.set(.2, .2);
    	closeXButton.alpha = 1;
    	FlxTween.tween(closeXButton.scale, { x:1, y:1 }, .5, { type: FlxTween.ONESHOT } );

  • You should keep track of your tweens and cancel them before closing your state.
    Or there's a better way but I haven't tried it yet:


  • @DleanJeans how would you go about tracking tween chains?

    something like this?

    FlxTween myTween = FlxTween.tween(this, { x:10 }).wait(10).then(FlxTween.tween(this, { x:0 }));

  • Better try the latter way.

  • My flixel version did not have completeAll so I updated and checked if it would work without any changes but it still didn't work. Then I tried


    and that didn't work either but then I tried


    and that worked

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.