Skip to main content
deborahb44958436
Inspiring
May 12, 2015
Answered

How to remove only after the Tween move is over

  • May 12, 2015
  • 1 reply
  • 432 views

I want the last statement removeChild(dropBall1); in this script, to be executed only after the Tween move is over. How do I do that? right now as it is, it gets removed right away.

function onClick10f1(e: MouseEvent) {

addChild(dropBall1)

removeChild(bigBall1)

dropBall1.x = 356.10;

dropBall1.y = 28;

var bigBDrop1: Tween = new Tween(dropBall1, "y", Regular.easeIn, 28, 156, 1, true);

removeChild(dropBall1);

This topic has been closed for replies.
Correct answer kglad

don't make tweens local to a function.  they're liable to be gc'd before completion and import the tweenevent:

var bigBDrop1: Tween

function onClick10f1(e: MouseEvent) {

addChild(dropBall1)

removeChild(bigBall1)

dropBall1.x = 356.10;

dropBall1.y = 28;

bigBDrop1 = new Tween(dropBall1, "y", Regular.easeIn, 28, 156, 1, true);

bigBDrop1.addEventListener(  fl.transitions.TweenEvent.MOTION_FINISH,tweenFinishF);

}

function tweenFinishF(e:TweenEvent):void{

removeChild(dropBall1);

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 12, 2015

don't make tweens local to a function.  they're liable to be gc'd before completion and import the tweenevent:

var bigBDrop1: Tween

function onClick10f1(e: MouseEvent) {

addChild(dropBall1)

removeChild(bigBall1)

dropBall1.x = 356.10;

dropBall1.y = 28;

bigBDrop1 = new Tween(dropBall1, "y", Regular.easeIn, 28, 156, 1, true);

bigBDrop1.addEventListener(  fl.transitions.TweenEvent.MOTION_FINISH,tweenFinishF);

}

function tweenFinishF(e:TweenEvent):void{

removeChild(dropBall1);

}

deborahb44958436
Inspiring
May 12, 2015

When trying your suggestions I get error: " Type was not found or was not a compile-time constant: TweenEvent." and I do have the "import fl.transitions.TweenEvent;" Also took the var out of local

kglad
Community Expert
Community Expert
May 12, 2015

yes, again and import the tweenevent.

i'm not sure what you mean 'took the var out of local', but the code i posted is what you should be using.

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.